繁体   English   中英

核心位置不在iOS模拟器上运行

[英]Core Location don't run on ios simulator

我的应用是由Xcode 5为ios7创建的,当我按下“获取位置”按钮时,出现了消息“ MyApp想要使用您的当前位置”,现在我更新了Xcode,并且在ios8核心位置上没有运行,缺少一些键加上? 还是上课? 在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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM