I'm struggling to develop a feature for an iPhone app:
1. User enter/leave a region
2. An endPoint is called
When app is relaunched by the system because of the region change, sometime the endPoint is called right away, sometimes after 2hours, sometimes never...
It seems that this issue started from iOS13.
I tried to stick as much as possible to Apple guidelines :
API is called from background (because app is in background state when relaunched by location update):
let configuration = URLSessionConfiguration.background(withIdentifier: identifier) configuration.sessionSendsLaunchEvents = true configuration.networkServiceType = .responsiveData configuration.sharedContainerIdentifier = "XXX.XXX.XXX" configuration.requestCachePolicy = .reloadIgnoringCacheData configuration.shouldUseExtendedBackgroundIdleMode = true let session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
I download the response instead of getting it:
I handle events for background URLSession
application(_ application : UIApplication, handleEventsForBackgroundURLSession identifier : String, completionHandler : @escaping () -> ())
App has got the following capability:
- Background Fetch
It works perfectly on the simulator.
On a real device it works about 75% of time.
I've also tried UIApplication.beginBackgroundTask but with no success.
So, my questions are:
- how can I have a 100% success endPoint call when region is changed (and network is available)?
- Am I using the right methods? Do I missed something?
- Is there a way to test it with the debugger? The issue I'm experiencing is only when app is closed and a region change event is triggered. The solution I found is to develop a small logging library that writes each events locally, so I can read them when I relaunch the app manually. It's not really handy to debug.
Thanks for your answers