【发布时间】:2013-09-25 23:50:06
【问题描述】:
我有一个非常奇怪的行为。我正在编写一个同时使用 fetch 和 location 后台模式的应用程序(不知道这对问题很重要)。我使用委托正确设置了 CLLocationManager,并开始监视 AppDelegate 中的重大位置更改 (startMonitoringSignificantLocationChanges)。 我立即被称为 didUpdateLocations,它给了我一些位置。之后,即使我在 Xcode 中模拟不同的位置(也使用 GPX 文件),甚至我停止并重新启动监视,也不会触发更多事件。我在后台和前台都没有收到任何位置。
奇怪的是,如果我开始更新位置(使用 GPS),它会正常工作(进行相同的测试......启动和停止与 startMonitoringSignificantLocationChanges 完全一样)。显然,我有 didUpdateLocations 和 didFailWithError(我没有收到任何错误)。
这是我的初始化(由我的 AppDelegate didFinishLaunchWithOptions 中的对象的初始化调用):
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
我知道 distanceFilter 和准确性对于重大的位置变化并不重要,我已经将 pausesLocationUpdatesAutomatically 设置为 NO。
我错过了什么吗?并且是否存在一种读取位置是否来自 wifi、蜂窝或 gps 的方法?
提前致谢。
【问题讨论】:
-
您知道
startMonitoringSignificantLocationChanges不使用 GPS,而是使用手机天线检查您是否移动了明显距离。所以也许这在模拟器中不起作用。
标签: iphone ios objective-c core-location