アプリの終了時にユーザーの場所の更新を取得したいと考えました。 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可能です
バックグラウンドロケーションの取得を有効にしましたか? – vivek
プロジェクト設定 - >機能 - >バックグラウンドモードの場所の更新で意味がある場合 –
[アプリケーションが停止されている場合でもiOS 7および8のロケーションアップデートを取得する方法](https://stackoverflow.com/questions/) 272742677/ios-7-and-eight-even-the-app-is-suspendedの方法を取得する方法 –