为什么CoreLocation(Mac OS X)不记得我允许使用它的选择?

时间:2015-02-07 01:26:05

标签: macos cocoa core-location

我可能非常愚蠢,但我无法解决为什么会发生以下情况:

我在Mac OS X上有一个使用CoreLocation的应用程序。以下是相关代码:

它要求每次启动时都允许使用我的位置,并且永远不会记得我已经授权使用位置数据。

该应用程序永远不会出现在'隐私'偏好窗格。

我错过了什么吗?

感谢。

#pragma mark - General Instance Methods

- (void)determineLocation
{
    if (self.locationManager)
    {
        DDLogWarn(@"determinLocation called, but we already have a locationManager instance variable...");
        DDLogWarn(@"This is a bug.");
    }

    self.currentlocationName = @"Location unknown";
    if (![CLLocationManager locationServicesEnabled])
    {
        DDLogWarn(@"Location Services not enabled.");
        [self fallBackToHardcodedLocation];
        return;
    }

    //  Location services are available.
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;


    //  Coarse-grained location accuracy required.
    self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
    self.locationManager.distanceFilter = 1000; // meters - 1km
    [self.locationManager startUpdatingLocation];
}



#pragma mark - Location Manager Delegate Methods


- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    DDLogVerbose(@"Our authorisation to use the location manager has changed.");
    switch (status) {
        case kCLAuthorizationStatusNotDetermined:
            DDLogError(@"LocationManager Authorisation status not determined. (User hasn't chosen yet)");
            break;

        case kCLAuthorizationStatusAuthorized:
            DDLogVerbose(@"We are now authorised for locationServices.");
            [self.locationManager startUpdatingLocation];
            break;

        case kCLAuthorizationStatusDenied:
            DDLogWarn(@"LocationManager: We are now explicitly denied!");
            [self.locationManager stopUpdatingLocation];
            break;

        case kCLAuthorizationStatusRestricted:
            DDLogWarn(@"LocationManager We are now restricted! (not authorised - perhaps due to parental controls...)");
            [self.locationManager stopUpdatingLocation];
            break;

        default:
            break;
    }
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    //  Main callback for location discovery..§

    CLLocation* location = [locations lastObject];
    NSDate* eventDate = location.timestamp;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
    if (abs(howRecent) < 15.0)
    {
        // Event is recent. Do something with it.
        if (location.horizontalAccuracy > 1000)
        {
            DDLogWarn(@"Location Accuracy is worse than 1km, discarding...");
        } else {
            [self updateLocation:location];
        }
        return;
    }

    DDLogWarn(@"Stale location data...");
    [self updateLocation:location];
}

它总是要求权限:( kCLAuthorizationStatusNotDetermined似乎总是如此。)

 2015-02-07 01:03:36:127 Central Heating[2260:30b] LocationManager Authorisation status not determined. (User hasn't chosen yet)

CoreLocation permission always asked (对话文本:&#34;中央供暖&#34;想要使用您当前的位置。天气预报需要您的位置。[不允许] [确定])

1 个答案:

答案 0 :(得分:1)

正如戈登提到的那样,通过签署申请来解决这个问题。