Home > Enterprise >  Execute code in the background when push notification is received iOS15
Execute code in the background when push notification is received iOS15

Time:04-16

I'm building an app which is running in the background and tracking significant location changes on the device.

Is it possible to send a push notification to the device and have the device send the current precise location to a server without needing the user to open the app so it runs in the foreground?

This previous SO answer doesn't seem to work anymore with iOS15. application:didReceiveRemoteNotification:fetchCompletionHandler does not seem to get called until I foreground the app. Is there a new method to achieve this functionality?

CodePudding user response:

There is a new feature since iOS 15: Location Push Service Extension (CLLocationPushServiceExtension - docs here). It is a power efficient way to query locations on iOS devices, even when your app isn’t running.

Please dive in into the docs and follow steps to configure Xcode project, add a Location Push Service Extension Target and implement Location Push functionality. Don't forget about proper entitlements and to request authorization for Location Services!

https://developer.apple.com/documentation/corelocation/cllocationmanager/creating_a_location_push_service_extension

  • Related