gpt4 book ai didi

iphone - Core Location 无法在 ios 模拟器上运行

转载 作者:行者123 更新时间:2023-12-03 20:51:06 25 4
gpt4 key购买 nike

我的应用程序是由 Xcode 5 for ios7 创建的,当我按下“获取位置”按钮时,出现消息“MyApp 希望使用您当前的位置”,现在我更新了 Xcode,在 ios8 核心位置上无法运行,缺少一些要添加的键?或某些类(class)?那在ios7中就不需要实现了?

最佳答案

iOS 8 CoreLocation API 已更改。

因此,您需要做的第一件事是将以下一个或两个键添加到您的 Info.plist 文件中:

NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

这两个键都采用一个字符串,该字符串描述了您为什么需要位置服务。您可以输入一个字符串,例如“需要位置才能找出您所在的位置”,与 iOS 7 一样,该字符串可以在 InfoPlist.strings 文件中进行本地化。

接下来您需要为相应的定位方法WhenInUse或Background请求授权。使用以下调用之一:

[self.locationManager requestWhenInUseAuthorization]
[self.locationManager requestAlwaysAuthorization]

下面的代码适用于 ios7 和 ios8 。

if (_locationmanager == nil) {
_locationmanager = [[CLLocationManager alloc] init];
}
_locationmanager.delegate = self;
_locationmanager.distanceFilter = kCLDistanceFilterNone;
if ([CLLocationManager locationServicesEnabled]) { // Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.

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

关于iphone - Core Location 无法在 ios 模拟器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26194091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com