当App处于Guided Access模式时,CLLocation Manager未更新 [英] CLLocation Manager not updated when App is in Guided Access mode

查看:102
本文介绍了当App处于Guided Access模式时,CLLocation Manager未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为iPad应用程序保留了Guided Access。当应用程序启动时,它使用 CLLocationManager 询问用户的当前位置。这在正常模式下工作并更新用户当前位置。但在Guided Access下,弹出窗口(允许访问您的位置)未显示, authorizationStatus 始终 kCLAuthorizationStatusNotDetermined 并且不更新用户的当前位置。无法理解可能是什么问题。搜索了很多但找不到它。

I kept Guided Access for iPad app. When the app is launched it asks for user's current location using CLLocationManager.This is working under Normal mode and updates user current location. But under Guided Access, popup ("Allow to access your location") is not shown and authorizationStatus is always kCLAuthorizationStatusNotDetermined and doesn't update current location of user . Couldn't understand what could be the problem.Searched a lot but couldn't find it.

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

}

任何建议都会有所帮助。谢谢!

Any suggestions would be helpful.Thank you !

推荐答案

首先设置 NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription .plist 中的code>。

At very first set NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription in your .plist.

添加 CoreLocation.framework 并在你的class.h文件中导入 - > #import< CoreLocation / CoreLocation.h> 然后设置 CLLocationManagerDelegate 到你的班级。

Add CoreLocation.framework and import in your class.h file -> #import <CoreLocation/CoreLocation.h> then set CLLocationManagerDelegate to your class.

声明 @property(强,非原子)CLLocationManager * locationManager;
初始locationManager并为其设置默认值。

Declare @property (strong, nonatomic) CLLocationManager *locationManager; Init locationManager and set default value to it.

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.....
}

这篇关于当App处于Guided Access模式时,CLLocation Manager未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆