位置应用终止时更新
问题描述:
我想在应用终止时获取用户位置更新。位置应用终止时更新
我试了一下: 在AppDelegate中:
var locationManger: CLLocationManager!
在的applicationDidFinishLaunching
setupLocationManager()
而且也AppDelegate中:
@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/ 27742677/how-to-get-location-updates-for-ios-7-and-8-even-when-the-app-is-suspended) –