How to start GPS tracking triggered by a iBeacon i

2019-05-29 01:24发布

问题:

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.

回答1:

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.



回答2:

Unfortunately, you can use CoreLocation geofences in the background, but you can't get fine GPS updates continually. This isn't a Xamarin thing -- it is an iOS restriction.

I wrote the blog post that @RobertN referenced about extending background beacon ranging to 3 minutes. But I don't think this is much help to you because you want to do get GPS updates continually, which Apple simply does not allow.



回答3:

The best explanation to this I seen can extend that 10 seconds to 3 minutes, but that is it... App rejection is an issue with continuous background operation unless your app truly is reviewed as a Navigation app:

A second approach involves tracking the beacon in the background, noting its estimated distance, and only triggering an action when the beacon is estimated to be within a specific range. This approach is problematic on iOS, because CoreLocation generally allows only 10 seconds of ranging time when an app is in the background. If a beacon is first detected at 50 meters, and a person is approaching the beacon at one meter per second, the mobile device will still be 40 meters away when iOS suspends the app and stops it from ranging.

The good news is that it is possible to extend background ranging time on iOS. If your app is a navigation app, you can specify location updates in the “Required background modes” in your Info.plist. But this approach makes it harder to get AppStore approval -- you have to convince reviewers that your app is providing navigation services to the user. This probably isn’t true for many apps that simply want to use beacons to trigger at a specific distance.

Fortunately, you can still extend background ranging time without requesting special background modes. The time you can get is limited -- only three minutes. But this clock restarts each time your app is woken up in the background, meaning you can get an extra three minutes of ranging time each time your app detects a beacon (enters a beacon region) or stops seeing beacons (exits a beacon region.)

Via: http://developer.radiusnetworks.com/2014/11/13/extending-background-ranging-on-ios.html