2015-09-17 7 views
6

場所のアクセス許可を処理する機能を作成しました。そのため、場所のアクセス権がないとアプリケーションが終了します。しかし、あなたが開いている設定を押して、ステータスバーの "アプリに戻る"を押すと、determeinePermissionメソッドは再度実行されません。私はそれをviewDidLoadviewDidAppearおよびviewWillAppearに追加しようとしました。私に何ができる?「back to app」が押されたことを検出しました

func determinePermission() { 
    switch CLLocationManager.authorizationStatus() { 

    case .Authorized: 
     if CLLocationManager.locationServicesEnabled() { 
      manager.delegate = self 
      manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters 
      manager.startUpdatingLocation() 
     } 


    case .NotDetermined: 
     manager.requestWhenInUseAuthorization() 
    case .AuthorizedWhenInUse, .Restricted, .Denied: 
     let alertController = UIAlertController(
      title: "Background Location Access Disabled", 
      message: "In order to be notified about adorable kittens near you, please open this app's settings and set location access to 'Always'.", 
      preferredStyle: .Alert) 

     let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in 
      exit(0) 
     } 
     alertController.addAction(cancelAction) 

     let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in 
      if let url = NSURL(string:UIApplicationOpenSettingsURLString) { 
       UIApplication.sharedApplication().openURL(url) 
      } 
     } 
     alertController.addAction(openAction) 

     self.presentViewController(alertController, animated: true, completion: nil) 
    } 
} 
+0

appDidBecameActiveに追加してみます。 P.S.あなたはあなたがしたいと言っているプログラム的にアプリケーションを閉じることはできません。コードにexit(0)を入れることはできません。 – Gruntcakes

+0

大丈夫です。私はその解決策を見つけるでしょう:)しかし、問題は –

+0

に戻るときにメソッドを呼び出すことですappDidBecomeActiveで試しましたか? – Gruntcakes

答えて

5

UIApplicationDelegate.applicationDidBecomeActiveに追加してください。

+1

であることを確認してください。それはapplicationDidBecomeActiveではありません。 '追加' – Max

+1

UIApplicationDidDidBecomeActiveは電話やSMSメッセージなどの一時的な中断の後でも起動しますので、代わりにUIApplicationDidEnterForegroundをお勧めします。 – Vadoff

関連する問題