【问题标题】:cllocationmanager not asking for user permission ios8cllocationmanager不要求用户权限ios8
【发布时间】:2014-11-14 18:13:29
【问题描述】:
这是我的代码:
if (!_locationManager)
{
_locationManager = [[CLLocationManager alloc] init];
[_locationManager setDelegate:self];
}
[_locationManager startUpdatingLocation];
如果有人知道请帮忙..谢谢
【问题讨论】:
标签:
objective-c
iphone
location
ios8
cllocationmanager
【解决方案1】:
使用iOS-8.0及以上版本的定位服务时,您需要添加对requestWhenInUseAuthorization的调用。找到下面的示例代码。
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
// this check is required for iOS 8+
// selector 'requestWhenInUseAuthorization' is first introduced in iOS 8
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
[locationManager startUpdatingLocation];
有关更多信息,请参阅blog。
希望这会有所帮助。
【解决方案2】:
将 [locationManager requestAlwaysAuthorization]; 添加到您的代码中,并将条目 NSLocationAlwaysUsageDescription 添加到您的 .plist 中,其值是您想要请求用户许可的某种消息。