startMonitoringSignificantLocationChanges,但过一会儿不再调用didUpdateLocations

编程入门 行业动态 更新时间:2024-10-28 03:20:31
本文介绍了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

本文发布于:2023-05-31 10:09:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/389612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:会儿   startMonitoringSignificantLocationChanges   didUpdateLocations

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!