Reputation: 8458
I'm updating an app which monitors for significant changes to the user's location using CLLocationManager. I allow the user to toggle this option on or off, setting startMonitoringSignificantLocationChanges and stopMonitoringSignificantLocationChanges appropriately.
The problem is when the user reopens the app I need to know if the app is currently monitoring significant locations or not in order to set the current state of this toggle accordingly.
Is there something I can check on the CLLocationManager or elsewhere, to tell me if the monitoring is currently on or off.
Upvotes: 2
Views: 1363
Reputation: 8458
So partly because of this annoying limitation on CLLocationManager I've ended up doing away with using Significant Location Changes in favour of monitoring regions. This has the advantage of being much more accurate than randomly getting a location when the cell tower changes, without draining the battery substantially, but more importantly you can ask the location manager which regions it's currently monitoring for, therefore finding out if it's on or off.
You can use it in much the same way as significant location changes as you can set a region up that's a radius around your current location and then on your didExitRegion callback, get a proper GPS signal and use the location from that.
Upvotes: 1
Reputation: 19790
In iOS 8, you can check the current permission that you get from the user. If the user gives you an Always
permission, that means that they allow significant location changes. If they only allow WhenInUse
, they don't allow significant location changes. See this post for details on what you get on the two location permissions.
Before iOS 8, I don't believe there's a way to tell that. The user can either allow you to use their location or not. Therefore you will need to keep track of the current status of the location manager yourself (i.e. have a BOOL
in NSUserDefaults
that changes to YES
when you call startMonitoringSignificantLocationChanges
, and set it to NO
when you call stopMonitoringSignificantLocationChanges
).
Upvotes: 1