Search code examples
iosxamaringpsbackground-processibeacon

How to start GPS tracking triggered by a iBeacon in Xamarin iOS?


I am working on an app that records journeys by tracking the GPS. Everything is working fine in background if we start the process from the foreground (by tapping the button "Start Journey"). Now the idea is start record these journeys automatically triggered by a iBeacon. When the iPhone gets inside of a beacon region, the app is detecting this and calls the function LocationManager.StartUpdatingLocation();

PROBLEM: Using iBeacons from background, we only get 10 seconds ranging and that is the same figure I have got to get location updates from GPS.

All I need is detect I am inside of beacon region, start GPS and keep it running, and only disable the GPS when I am outside of the region.


Solution

  • We actually recently wanted to implement this behavior in one of our apps too, and found that if we start significant location updates (startMonitoringSignificantLocationChanges) in the foreground, then we're able to start regular location updates (startUpdatingLocation) in the background, in our didEnterRegion implementation.

    (Naturally, your app needs the "always" authorization to access Location Services, and the "Location updates" Background Mode enabled.)

    Our app is still pending review, so whether that's a bug or a feature of Core Location, and whether Apple is okay with that, remains to be seen.