【问题标题】:Location services error after upgrading to iOS8升级到 iOS8 后定位服务出错
【发布时间】:2015-01-27 10:43:45
【问题描述】:

我正在尝试支持 iOS7 和 8 定位服务。当我在我的 iOS8 设备上运行时,我收到了这个错误:

"MyApp depending on legacy on-demand authorization, which is not supported for new apps"

我的 plist 中有一个 when in use 条目。这是我的代码:

    if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [_locationManager requestWhenInUseAuthorization];
    } else {
        [_locationManager startUpdatingLocation];
    }


- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
  if (status == kCLAuthorizationStatusAuthorizedWhenInUse) {
    [_locationManager startUpdatingLocation];
  }
}

为什么会出现这个错误?

【问题讨论】:

  • 这个错误出现在哪里?
  • 这个错误出现在 iOS 模拟器 > 调试 > 系统日志

标签: objective-c ios8 core-location


【解决方案1】:

我正在从位置服务实施一个已弃用的回调,而不是实施新的回调。没有编译器警告,但阅读此内容的开发人员应检查其代码中位置服务委托的文档。

已弃用它是委托文档中的第一个方法。整个问题都是 RTFM 的一个案例。

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_6, __MAC_NA, __IPHONE_2_0, __IPHONE_6_0);

【讨论】:

  • 你能告诉你使用的不推荐使用的回调是什么吗?
  • 哇,为什么会被标记下来?我对自己的问题给出了正确的答案。我现在不在代码中,但它与验证用户权限有关。
  • 您的答案可以更具体。似乎在您的问题解决之后,您并不关心可能遇到相同问题的其他人。分享您的答案的细节可能会被视为慷慨。
  • 很公平。我不记得它是哪个回调。我打开了 in-IDE 文档,看到我的回调“已弃用”。
【解决方案2】:

您在 swift 中收到此错误的原因是您没有要求用户明确允许使用位置服务,这在 iOS 8 之前都很好。 从 iOS 8 开始,您应该明确请求使用位置服务的权限。

iOS 版本 >= 8

self.locationManager.requestAlwaysAuthorization()
self.locationManager.startMonitoringSignificantLocationChanges()

iOS版本

self.locationManager.startMonitoringSignificantLocationChanges()

【讨论】:

    【解决方案3】:

    在 info.plist 中添加这两个键,值字符串“需要位置才能找出您所在的位置”。

    NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-19
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      相关资源
      最近更新 更多