ロケーションが必要な画面で、ロケーションサービスが有効かどうかを確認してください。
override func viewDidLoad()
{
super.viewDidLoad()
self.checkLocationServiceEnabled()
}
func checkLocationServiceEnabled()
{
let locationAuthorizationStatus = CLLocationManager.authorizationStatus()
switch locationAuthorizationStatus {
case .AuthorizedAlways ,.AuthorizedWhenInUse ,.NotDetermined ,.Restricted:
break
case .Denied:
self.alertTurnOnLocationFromDevicePrivacySetting()
}
}
func alertTurnOnLocationFromDevicePrivacySetting()
{
let delayTime = dispatch_time(DISPATCH_TIME_NOW,
Int64(1 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
let alertController = UIAlertController(
title: ALERT_TURN_ON_LOCATION_FROM_DEVICE_PRIVACY,
message: "",
preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: ALERT_OK, style: .Cancel, handler: nil)
alertController.addAction(cancelAction)
self.navigationController?.topViewController!.presentViewController(alertController, animated: true, completion: nil)
}
}
あなたは 'CLLocationManager'と' CLLocationManagerDelegate'を見ましたか? – Callam
MKMapViewはこれをすべて行います...「タイマー」を使用する必要はありません。 (http://stackoverflow.com/a/11675587/499581参照) –