I am also experiencing unreliable geofence entry & exit events since iOS 18. With iOS 17, I didn't need to use a CLServiceSession
at all, now even when using one, it's unreliable. I also see the same behavior of the events timestamp to be the current time, and not the time of actual geofence entry.
I made sure the app has the "Always" permission but I did not set the new NSLocationRequireExplicitServiceSession
key in the Info.plist (I tested it, but couldn't see any change in the reliability)
What I am confused about is whether to start a CLServiceSession if the app is restarted in the background. Apple is not clear about it. In the WWDC session they say:
... So your job, ..., is to make sure that your process launch logic knows what features it has been tasked with pursuing, and re-takes session objects...
https://developer.apple.com/videos/play/wwdc2024/10212?time=758
But on the other hand it's also said that:
you can only start holding one (a CLServiceSession) when your app is in the foreground
https://developer.apple.com/videos/play/wwdc2024/10212?time=522
and also
... CLMonitor.events won’t yield results when it is not in use, unless a session which was started in the foreground, ....
https://developer.apple.com/videos/play/wwdc2024/10212?time=663
It is also not clear if we need to use CLLocationManager.allowsBackgroundLocationUpdates
(which is documented as "Apps that receive location updates when running in the background must include the UIBackgroundModes key (with the location value) in their app’s Info.plist file"). However, in my tests, doing so didn't yield any improvement (and as I said, in iOS 17 it wasn't required either).
@Engineer what makes me doubt this being the cause for the unreliability of the geofencing is that it worked perfectly with iOS 17.