没有更新CLLocation管理器时,应用程序是在引导模式下访问(CLLocation Manage

2019-10-23 10:00发布

我一直对iPad应用指导访问。 当应用程序被启动,它要求使用用户的当前位置CLLocationManager 。这是在正常模式和更新用户当前位置的工作。 但指导下的访问, popup ("Allow to access your location")未显示的并authorizationStatus总是kCLAuthorizationStatusNotDetermined并且不更新的用户的当前位置。 不明白什么可以在problem.Searched了很多,但无法找到它。

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];

}

任何建议将是helpful.Thank你!

Answer 1:

在最初的设定NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription在你.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.....
}


文章来源: CLLocation Manager not updated when App is in Guided Access mode