我有一个应用程序,我正试图获得LocationManager的授权才能出现。我总是让它起作用,但在使用时我试了一下。现在我不能让两个人一起工作了
我已将NSLocationWhenInUseUsageDescription字符串启用为在Info.plist中播放
在我的应用程序代表中我把
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate= self;
return YES;
}
- (void)locationManager:(CLLocationManager *)manager
didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorized){
NSLog(@"ok");
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedAlways){
NSLog(@"Always");
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){
NSLog(@"WhenInUse");
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusRestricted){
NSLog(@"restricted");
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
NSLog(@"denid");
AlertView2 = [[UIAlertView alloc] initWithTitle:@"App Permission Denied"
message:@"Please go to Settings/Privacy/Location Services to enable Always for this app to function properly."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[AlertView2 show];
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined){
NSLog(@"undetermined");
[self.locationManager requestWhenInUseAuthorization];
}
}我不确定这是我最初的,但我已经尝试了每一个可能的配置,虽然显然没有。
有人能帮我把这东西修好吗。我更喜欢WhenInUse,但现在我想要任何东西
顺便说一句,我在上一次状态中得到了NSLog的回调,但没有调用包含的代码。
谢谢你的帮助。
发布于 2016-03-12 17:31:55
所以我正式是个白痴。我看了看我的info.plist,它就在那里。我复制并粘贴了Alway描述,并将其更改为WhenInUse,当它不起作用时,我删除了原件并保存了副本,并将其更改为“始终不变”。但是,在展开列以查看整个内容时,是将a-2附加到末尾,因此格式不正确,因此无法工作。一旦我删除了-2,它的工作非常好。我已经更改了原来的帖子,以显示它是如何工作的。谢谢你的帮助,我会确保我能解决你提出的问题。
发布于 2016-03-12 00:54:09
有几个想法:
delegate。authorizationStatus?您应该在麻烦请求权限之前检查它,因为如果他们已经拒绝了权限,则需要告诉他们修复设置。如果权限以前被拒绝,请求权限将不会导致任何事情(包括状态的更改)。发布于 2016-03-12 04:13:57
试试这个..。
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = 1000.0f;
[locationManager requestAlwaysAuthorization];
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];https://stackoverflow.com/questions/35951725
复制相似问题