【问题标题】:startMonitoringSignificantLocationChanges but after some time didUpdateLocations is not called anymorestartMonitoringSignificantLocationChanges 但一段时间后不再调用 didUpdateLocations
【发布时间】: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


【解决方案1】:

您只能使用模拟器位置菜单中的“高速公路驾驶”选项来模拟模拟器上发生重大变化的位置。每隔几分钟就会触发一次。

【讨论】:

    【解决方案2】:

    在主线程上分配管理器并检查管理器或应用程序是否始终具有权限可以解决问题。 苹果的文档说明是:

    注意:重大更改位置更新需要授权 kCLAuthorizationStatusAuthorizedAlways 的状态。

    您可以使用以下方式检查状态:

    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    

    也许

    if (status != kCLAuthorizationStatusAuthorizedAlways)
    

    您可以再次请求权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多