更新:这不是重复.我已经在info.plist中添加了所需的密钥,如我原始问题中所述,问题仍然存在.我已经尝试了各种组合的所有三个键.
在任何人感到不安之前,我已阅读了许多Apple Dev论坛帖子和堆栈溢出帖子,无法弄清楚为什么我的应用程序拒绝提示用户允许使用时授权.
我已将以下密钥添加到我的Info.plist文件中,并附带一个String值:
NSLocationWhenInUseUsageDescription
然后我写了(在Swift和Obj-C中)应该提示用户的代码:
@property CLLocationManager *location; ... @synthesize location; ... location = [[CLLocationManager alloc] init]; location.delegate = self; location.desiredAccuracy = kCLLocationAccuracyBest; location.distanceFilter = kCLDistanceFilterNone; [location requestWhenInUseAuthorization]; [location startUpdatingLocation]; I'm using the following CLLocationManagerDelegate methods. - (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations - (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
这基本上是直接从Apple“LocateMe”示例代码中复制的.
无论我尝试什么样的各种序列或细微的变化,应用程序都不会提示允许授权.我已经使用switch语句来确定[CLLocationManager authorizationStatus]的状态,但是不断收到“未确定”的响应.
if ([CLLocationManager locationServicesEnabled]) { switch ([CLLocationManager authorizationStatus]) { case kCLAuthorizationStatusAuthorizedAlways: NSLog(@"Always Authorized"); break; case kCLAuthorizationStatusDenied: NSLog(@"Denied"); break; case kCLAuthorizationStatusAuthorizedWhenInUse: NSLog(@"Authorized in Use"); break; case kCLAuthorizationStatusNotDetermined: NSLog(@"Not Determined"); break; case kCLAuthorizationStatusRestricted: NSLog(@"Restricted"); break; } }
任何帮助将不胜感激.我正在运行带有iOS 8.1.2物理设备的Xcode 6.2(6C101)和用于测试的iOS 8.2(12D5452a)模拟器.
解决方法
这里有很多有用的比较:
http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/
此外,愚蠢的问题时间:你混合_location和self.location但你没有显示你的属性/综合代码.你确定你在同一个物体上操作吗?