我试图在 iOS 8 上使用 MapKit,但我一直收到错误:
Trying to start MapKit location updates without prompting for location authorization. Must call
-[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager
requestAlwaysAuthorization] first.
在这里查找,我发现我必须在我的 plist 中实现 NSLocationWhenInUsageDescription,但没有任何反应,我仍然在控制台中收到该错误。我做错了什么?
最佳答案
1.- 将以下行添加到您的 info.plist
<key>NSLocationWhenInUseUsageDescription</key>
<string>The spirit of stack overflow is coders helping coders</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>I have learned more on stack overflow than anything else</string>
2.- 位置授权提示:
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
3.-当用户接受时更新位置...
- (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
[self.locationManager startUpdatingLocation];
}
}
关于ios - 尝试启动 MapKit 位置更新而不提示在 ios 9 中使用 objective-c 进行位置授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33793062/