-
-
Save AppleCEO/52e2ed11df0c5553c230c3a699c84d81 to your computer and use it in GitHub Desktop.
스위프트 : 위치정보 사용 권한에 따른 예외처리 추가하기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import CoreLocation | |
class ViewController: UIViewController, CLLocationManagerDelegate { | |
// 중략 | |
@IBOutlet var requestWeatherButton : UIButton! | |
override func viewDidAppear(animated: Bool) { | |
super.viewDidAppear(animated) | |
requestWeatherButton.enabled = false | |
let status = CLLocationManager.authorizationStatus() | |
if status == CLAuthorizationStatus.Denied || status == CLAuthorizationStatus.Restricted { | |
let alert = UIAlertController(title: "위치정보", message: "설정에서 위치정보 사용을 위해 권한을 허용해주세요", preferredStyle: UIAlertControllerStyle.Alert) | |
alert.addAction(UIAlertAction(title: "확인", style: UIAlertActionStyle.Cancel, handler: nil)) | |
presentViewController(alert, animated: true, completion: nil) | |
} | |
else if status == CLAuthorizationStatus.AuthorizedWhenInUse { | |
requestWeatherButton.enabled = true | |
} | |
} | |
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { | |
if status == CLAuthorizationStatus.AuthorizedWhenInUse { | |
requestWeatherButton.enabled = true | |
} | |
} | |
// 생략 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment