startMonitoringSignificantLocationChanges but after some time didUpdateLocations is not called anymore

ε祈祈猫儿з 提交于 2019-12-24 03:46:06

问题


I have a very strange behaviour. I'm writing an application that uses both fetch and location background mode (don't know it it's important for the problem). I correctly set up the CLLocationManager with a delegate and I start monitoring significant location changes (startMonitoringSignificantLocationChanges) in the AppDelegate. Immediately I get called didUpdateLocations that gives me some locations. After that no more events are fired even I simulate a different location in Xcode (also using a GPX file) and even I stop and restart the monitoring. I'm not receiving any location both in background and foreground.

The strange thing is that if I start updating locations (using the GPS) it works correctly (doing the same tests... starting and stopping exactly like with startMonitoringSignificantLocationChanges). Obviously I've both didUpdateLocations and didFailWithError (I receive no errors).

This is my initialisation (called by the initialisation of an object in my AppDelegate didFinishLaunchWithOptions):

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;

I know that distanceFilter and accuracy are not important for significant location changes and I've already set pausesLocationUpdatesAutomatically to NO.

Am I missing something? And also does exist a way to read if a location fired is coming from wifi, cellular or gps?

Thanks in advance.


回答1:


You can simulate location for significant change on simulator only with "freeway drive" option from simulator location menu. It will be triggered with some minutes interval.




回答2:


Allocate the manager on the main thread and check if the manager or the app has always permissions could do the trick. Apple's documentation note is:

Note: Significant-change location updates require an authorization status of kCLAuthorizationStatusAuthorizedAlways.

You can check the status using:

CLAuthorizationStatus status = [CLLocationManager authorizationStatus];

And maybe

if (status != kCLAuthorizationStatusAuthorizedAlways)

You can request permissions again.



来源:https://stackoverflow.com/questions/18919333/startmonitoringsignificantlocationchanges-but-after-some-time-didupdatelocations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!