【问题标题】:Cannot retrieve device location无法检索设备位置
【发布时间】:2014-10-29 17:27:17
【问题描述】:

我正在尝试获取设备的纬度/经度,并且完全按照本教程进行操作。 http://ios-blog.co.uk/tutorials/getting-the-users-location-using-corelocation/

当我运行程序时,标签应该更新为纬度和经度(我将模拟器的位置设置为“Apple”,但标签根本不更新。我也从来没有收到提示我允许应用程序使用设备的位置。我尝试从模拟器中删除应用程序并重新运行它,但这并没有改变任何东西。

有人知道为什么这不起作用吗?我想知道这是否与最新版本的 Xcode(我正在使用 6)与适用于先前版本的教程无关。想法?

【问题讨论】:

    标签: ios xcode xcode6 core-location


    【解决方案1】:

    您需要在 info.plist 中添加一个 NSLocationWhenInUseUsageDescription 密钥。

    您还需要调用:

    locationManager = [[CLLocationManager alloc] init];
    [locationManager requestWhenInUseAuthorization];
    

    【讨论】:

      【解决方案2】:

      如果您正在为 iOS 8 构建,您是否在启动 CLLocationManager 之前要求授权,如此处所述?:Xcode 6/iOS 8 Location Simulation doesn't work

      本质上,调用以下方法之一:

      [self.locationManager requestWhenInUseAuthorization];  // For foreground access
      [self.locationManager requestAlwaysAuthorization]; // For background access
      

      【讨论】:

      • 做到了,除了添加到 info.plist 中。非常感谢!我为此搜索了 SO,但没有指定 ios8,所以这可能就是我没有找到答案的原因。现在我知道下次了!
      猜你喜欢
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-11
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      相关资源
      最近更新 更多