Issue with geolocation without using maps

I have an application that uses geolocation to track the user’s location and trigger actions when the app is in either the foreground or background. Currently, it seems that region entry is not triggered unless an app like Maps (which actively uses location services) is opened. The location permissions are correctly set to “Always” with precise location enabled. We are using geofencing to setup region and trigger actions when entering or leaving.

Is there something I’m missing in the configuration that could be preventing region monitoring from triggering properly when the app is in use or in background?

It wouldn't be possible to guess what you would be missing without seeing a project, but my first suspicion would be perhaps you are using regions that are too small for the location you are at.

Region Monitoring or the CLMonitor functionality rely on WiFi or Cellular signals and the accuracy/region radius you can work with is limited to the availability of signals in the area. While you can expect a 100-200 meter radius region to work reliably in a busy downtown area with plenty of WiFi and Cellular signals, in a remote rural area, you may find that a radius of a kilometer or more would be needed to reliably trigger entry/exit events.

Most common cause we see is this, and developers choosing very small regions (50 meters or smaller) that makes it improbable to have enough granular location information.


Argun Tekant /  DTS Engineer / Core Technologies

Are you using CLMonitor? I have the same problem where it's random which location that is triggered. I have 16 locations as test.

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.

While these things you mention may effect whether your app gets location updates in the background at all, they will not effect the reliability of CLMonitor regions. Like I mentioned, the most common cause for reliability is insufficient region size for the coverage in a certain location.

If you believe that this is something else, we would like some more detailed information so we can take a look at what might be happening.

For our engineering teams to investigate this issue, as this might indicate an issue with iOS 18 like you imply, we'd greatly appreciate it if you could open a bug report, include repro steps and sample code that reproduce the issue, and post the FB number here once you do.

Bug Reporting: How and Why? has tips on creating a successful bug report.

It would be very helpful if you could please go to https://developer.apple.com/bug-reporting/profiles-and-logs/ and follow the instructions for Location Services for iOS to install a logging profile on your device. Then reproduce the issue, and follow the instructions at the above link to create a sysdiagnose. And attach that to the Feedback report as well

Issue with geolocation without using maps
 
 
Q