在我的viewDidLoad
方法中我有
locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
locationManager.delegate = self; // we set the delegate of locationManager to self.
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
[locationManager requestWhenInUseAuthorization];
}
并且调用了请求,但是没有提示用户?为什么?
您可能需要更新您的plist
文件。这是一个tutorial how to do it,快速和脏:
您需要做的是将以下键之一添加到Info.plist文件中:
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
您还需要请求相应位置方法WhenInUse
或Background
的授权。使用以下电话之一:
[self.locationManager requestWhenInUseAuthorization]
[self.locationManager requestAlwaysAuthorization]
还有一篇帖子我觉得很有帮助:
Location Services not working in iOS 8
这个答案详细说明how to update your plist
file:
将以下行之一添加到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>
你可能想要在shipping the code之前定制和拼写检查info.plist文件中字典条目的字符串。