【问题标题】:Always On Location Not Being Requested始终在位置不被请求
【发布时间】:2014-10-20 13:58:20
【问题描述】:

我问这个是因为我有点困惑。我确实在Info.plist 中设置了NSLocationAlwaysUsageDescription,这是我正在运行的代码:

CLLocationManager *locMan = [[CLLocationManager alloc] init];
locMan.delegate = self;
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways)
{
    [locMan requestAlwaysAuthorization];
}

[locMan startUpdatingLocation];

我设置了一个断点并验证了它确实被调用了,但我没有在应用程序中收到警报。我检查了我的隐私设置,并看到该应用程序有一个带有两个选项的条目:无和始终,都没有选中。我尝试卸载、清理和重新安装,但仍然无法正常工作。有什么想法吗?

编辑: 我将上面的块从viewDidLoad 移动到viewDidAppear:,现在警报出现并在半秒后消失

【问题讨论】:

    标签: ios objective-c core-location cllocationmanager


    【解决方案1】:

    我解决了我的问题。是留存问题。我在本地声明了我的CLLocationManager,所以当它到达我的方法的末尾时,它就不再存在了,这就解释了为什么它不能请求许可。我将它推广为一个属性,现在一切正常

    【讨论】:

      【解决方案2】:

      您需要在代码末尾添加这一行

      [self.locationManager startUpdatingLocation];
      

      【讨论】:

        【解决方案3】:

        如果你试试这个呢:

        CLLocationManager *locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        
        if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
            [locationManager requestWhenInUseAuthorization];
        }
        
        [locationManager startUpdatingLocation];
        

        抱歉,误读了您的帖子。也许试试这个:

        CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
        
        if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusDenied) {
            // Show alert or something
        }
        else if (status == kCLAuthorizationStatusNotDetermined) {
            [self.locationManager requestAlwaysAuthorization];
        }
        

        更多内容可以在这里阅读:Core Location Manager Changes in iOS 8

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-08-26
          • 2023-03-23
          • 2012-04-23
          • 1970-01-01
          • 2017-05-12
          • 2021-02-01
          相关资源
          最近更新 更多