I wanted to get user location updates when the app gets terminated.
What I tried: In AppDelegate:
var locationManger: CLLocationManager!
In the applicationDidFinishLaunching
setupLocationManager()
And also in 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)
}
}
But i dont get a push notification... Any ideas? Referring to this post: IOS Getting location updates when app terminated without using significantChange it should be possible