2017-09-08 13 views
1

アプリの終了時にユーザーの場所の更新を取得したいと考えました。 AppDelegateで :AppDelegateで場所の更新中にアプリが終了しました

var locationManger: CLLocationManager! 
applicationDidFinishLaunchingで

setupLocationManager() 

も:私が試した何

@nonobjc func applicationWillTerminate(application: UIApplication) { 
     locationManger.startMonitoringSignificantLocationChanges() 
    } 
func setupLocationManager(){ 
     locationManger = CLLocationManager() 
     locationManger.delegate = self 
     locationManger.requestAlwaysAuthorization() 
     locationManger.desiredAccuracy = kCLLocationAccuracyHundredMeters 
    } 

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
     if UIApplication.shared.applicationState == .inactive{ 
      let notification = UNMutableNotificationContent() 
      notification.title = "Location Update" 
      notification.body = "updated in background" 

      let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) 
      let request = UNNotificationRequest(identifier: "locationUpdate", content: notification, trigger: notificationTrigger) 

      UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) 
     } 

    } 

しかし、私はプッシュ通知を取得いけません。.. 。 アイデアはありますか? この投稿を参照してください:IOS Getting location updates when app terminated without using significantChange可能です

+0

バックグラウンドロケーションの取得を有効にしましたか? – vivek

+0

プロジェクト設定 - >機能 - >バックグラウンドモードの場所の更新で意味がある場合 –

+0

[アプリケーションが停止されている場合でもiOS 7および8のロケーションアップデートを取得する方法](https://stackoverflow.com/questions/) 272742677/ios-7-and-eight-even-the-app-is-suspendedの方法を取得する方法 –

答えて

0

ここでバックグラウンドフェッチを有効にしましたか? enter image description here

+0

この窓を見つけるにはどこですか? –

+0

これはEdit Schemeです。 Xcodeの左上にはターゲットが表示され、そこからドロップダウンリストから編集スキームを選択できます – prabodhprakash

関連する問題