首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >locationManager授权无效

locationManager授权无效
EN

Stack Overflow用户
提问于 2016-03-11 23:26:58
回答 3查看 279关注 0票数 0

我有一个应用程序,我正试图获得LocationManager的授权才能出现。我总是让它起作用,但在使用时我试了一下。现在我不能让两个人一起工作了

我已将NSLocationWhenInUseUsageDescription字符串启用为在Info.plist中播放

在我的应用程序代表中我把

代码语言:javascript
复制
- (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的回调,但没有调用包含的代码。

谢谢你的帮助。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-03-12 17:31:55

所以我正式是个白痴。我看了看我的info.plist,它就在那里。我复制并粘贴了Alway描述,并将其更改为WhenInUse,当它不起作用时,我删除了原件并保存了副本,并将其更改为“始终不变”。但是,在展开列以查看整个内容时,是将a-2附加到末尾,因此格式不正确,因此无法工作。一旦我删除了-2,它的工作非常好。我已经更改了原来的帖子,以显示它是如何工作的。谢谢你的帮助,我会确保我能解决你提出的问题。

票数 0
EN

Stack Overflow用户

发布于 2016-03-12 00:54:09

有几个想法:

  • 我建议在请求许可之前设置delegate
  • 在请求许可之前,什么是authorizationStatus?您应该在麻烦请求权限之前检查它,因为如果他们已经拒绝了权限,则需要告诉他们修复设置。如果权限以前被拒绝,请求权限将不会导致任何事情(包括状态的更改)。
票数 0
EN

Stack Overflow用户

发布于 2016-03-12 04:13:57

试试这个..。

代码语言:javascript
复制
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.desiredAccuracy  = kCLLocationAccuracyBest;
locationManager.distanceFilter = 1000.0f;
[locationManager requestAlwaysAuthorization];
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35951725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档