【问题标题】:Mac CoreLocation Services does not ask for permissionsMac CoreLocation Services 不请求权限
【发布时间】:2012-06-30 13:27:58
【问题描述】:

我正在编写一个需要使用 CoreLocation 服务的 Mac 应用程序。只要我在安全首选项窗格中手动验证服务,代码和位置就可以正常工作。但是,该框架不会自动弹出权限对话框。文档指出:

重要用户可以选择拒绝应用程序的访问 到位置服务数据。在其最初使用期间 应用程序,核心位置框架提示用户确认 使用定位服务是可以接受的。如果用户拒绝 请求,CLLocationManager 对象报告一个适当的错误给 在以后的请求中它的委托。

我的委托确实收到了一个错误,并且 +locationServicesEnabled 的值在 CLLocationManager 上是正确的。唯一缺少的部分是向用户提示有关权限的提示。这发生在我的开发 MPB 和一个朋友的 MBP 上。我们俩都搞不清楚哪里出了问题。

有人遇到过这种情况吗?

相关代码:

_locationManager = [CLLocationManager new];    
[_locationManager setDelegate:self];
[_locationManager setDesiredAccuracy:kCLLocationAccuracyKilometer];
...
[_locationManager startUpdatingLocation];

【问题讨论】:

  • 向我们提供错误的完整详细信息以供开始
  • 这是 CoreLocation 框架在无法定位用户时给出的一般错误。 'kCLErrorLocationUnknown'
  • 请您提供错误报告的雷达 ID,我会尽快查看。
  • 好的,抱歉耽搁了。 ID 是:11791451。谢谢!

标签: macos cocoa core-location


【解决方案1】:

我发现在 Mac 上,当您通过调用启动定位服务时

[locationManager startUpdatingLocation];

触发

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status

状态为

kCLAuthorizationStatusNotDetermined

如果您查看此状态,然后再次开始更新位置,则会触发权限对话框:例如

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    switch (status) {
        case kCLAuthorizationStatusAuthorized:
            NSLog(@"Location Services are now Authorised");
            [_locationManager startUpdatingLocation];

            break;

        case kCLAuthorizationStatusDenied:
            NSLog(@"Location Services are now Denied");
            break;

        case kCLAuthorizationStatusNotDetermined:
            NSLog(@"Location Services are now Not Determined");

            //  We need to triger the OS to ask the user for permission.
            [_locationManager startUpdatingLocation];
            [_locationManager stopUpdatingLocation];

            break;

        case kCLAuthorizationStatusRestricted:
            NSLog(@"Location Services are now Restricted");
            break;

        default:
            break;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 2019-09-03
    • 2020-06-29
    • 1970-01-01
    相关资源
    最近更新 更多