startMonitoringSignificantLocationChanges,但过一会儿不再调用didUpdateLocations [英] startMonitoringSignificantLocationChanges but after some time didUpdateLocations is not called anymore

查看:455
本文介绍了startMonitoringSignificantLocationChanges,但过一会儿不再调用didUpdateLocations的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的行为。我正在编写同时使用提取和位置背景模式的应用程序(不知道它对问题的重要性)。我使用委托正确设置了CLLocationManager,并开始监视AppDelegate中的重大位置更改( startMonitoringSignificantLocationChanges )。
立即我叫出didUpdateLocations,它给了我一些位置。之后,不再触发任何事件,即使我在Xcode中模拟另一个位置(也使用GPX文件),甚至停止并重新启动监视。我在后台和前景都没有收到任何位置。



奇怪的是,如果我开始更新位置(使用GPS),则可以正常工作(执行相同的操作)测试...的启动和停止与startMonitoringSignificantLocationChanges完全相同。显然,我都做了didUpdateLocations和didFailWithError(我没有收到任何错误)。 p>

  self.locationManager = [[CLLocationManager alloc] init]; 
self.locationManager.delegate =自我;
self.locationManager.pausesLocationUpdatesAutomatically =否;

我知道distanceFilter和准确性对于重要的位置更改并不重要,并且我已经设置了pauseLocationUpdatesAutomatically自动为否。



我错过了什么吗?而且还存在一种读取位置是否来自wifi,蜂窝或gps的方法吗?



预先感谢。

解决方案

仅在模拟器位置菜单中使用高速公路驱动器选项,才能在模拟器上模拟显着变化的位置。它会每隔几分钟触发一次。


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.

解决方案

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.

这篇关于startMonitoringSignificantLocationChanges,但过一会儿不再调用didUpdateLocations的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆