Менеджер CLLocation не обновляется, когда приложение находится в режиме управляемого доступа

Я сохранил приложение Guided Access для iPad. Когда приложение запускается, оно запрашивает текущее местоположение пользователя, используя CLLocationManagerЭто работает в обычном режиме и обновляет текущее местоположение пользователя. Но в режиме управляемого доступа, popup ("Allow to access your location") не отображается и authorizationStatus всегда kCLAuthorizationStatusNotDetermined и не обновляет текущее местоположение пользователя. Не мог понять, в чем может быть проблема. Много искал, но не смог найти.

ViewController.m :

- (void)viewDidAppear:(BOOL)animated
{
    [appDelegate startLocation];
[self performSelector:@selector(CheckLocationManger) withObject:nil afterDelay:0.1];
}

-(void)CheckLocationManger
{
    AppAppDelegate *appDelegate=(AppAppDelegate*)[[UIApplication sharedApplication]delegate];


    if(![CLLocationManager locationServicesEnabled])
    {
        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Whoops we can’t find you!" message:@"Location services are disabled" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        if(activityIndictr)
            [activityIndictr stopAnimating];
        [alert1 show];


        return;
    }
    if([CLLocationManager locationServicesEnabled])
    {
        if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied)
        {

            UIAlertView  *alert1 = [[UIAlertView alloc] initWithTitle:@"Whoops we can’t find you!"message:@"Location services are disabled. You can fix this by going to Settings > Privacy > Location" delegate:nil cancelButtonTitle:@"OK"  otherButtonTitles:nil];
            if(activityIndictr)
                [activityIndictr stopAnimating];
            [alert1 show];
            return;
        }
        if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined) //This is called 
        {

    [self performSelector:@selector(CheckLocationManger) withObject:self afterDelay:0.1];  

            return;
        }

    }

    if(![self connected])
    {

        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Network Error" message:@"Please verify that you have internet connectivity" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        if(activityIndictr)
            [activityIndictr stopAnimating];
        [alert1 show];
        [alert1 release];
        return;


    }
    else {
        //continue further process

    }

}


AppDelegate.m

- (void)startLocation
{

    self.locationManager = [[[CLLocationManager alloc] init]autorelease];
    self.locationManager.pausesLocationUpdatesAutomatically=NO;
    [self.locationManager setDelegate:self];
    if([[[UIDevice currentDevice ]systemVersion] floatValue]>=8.0)
        {

          if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
                [self.locationManager requestWhenInUseAuthorization]; //is executed but popup never displays 
            }

        }

        [self.locationManager startUpdatingLocation];

}

Любые предложения будут полезны. Спасибо!

1 ответ

На самом первом сете NSLocationWhenInUseUsageDescription или же NSLocationAlwaysUsageDescription в вашем .plist,

добавлять CoreLocation.framework и импортировать в ваш файл class.h -> #import <CoreLocation/CoreLocation.h> затем установить CLLocationManagerDelegate в ваш класс.

декларировать @property (strong, nonatomic) CLLocationManager *locationManager;Инициируйте locationManager и установите для него значение по умолчанию.

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[self.locationManager setDistanceFilter:200.0f];
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])    // Or if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
    [self.locationManager requestAlwaysAuthorization];                                      // Or [self.locationManager requestWhenInUseAuthorization];
[self.locationManager startUpdatingLocation];

Воплощать в жизнь CLLocationMAnager метод делегата

#pragma mark - Location Delegate

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"updated coordinate are %@", [locations lastObject]);
    CLLocation *currentLocation =  [locations lastObject];
    // Your code.....
}
Другие вопросы по тегам