gpt4 book ai didi

ios - 当应用程序处于引导访问模式时,CLLocation 管理器未更新

转载 作者:行者123 更新时间:2023-11-29 10:28:32 25 4
gpt4 key购买 nike

我保留了 iPad 应用程序的引导访问。当应用程序启动时,它会使用 CLLocationManager 询问用户的当前位置。这在正常模式下工作并更新用户当前位置。但在 Guided Access 下,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];

}

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

最佳答案

首先设置NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription在你的.plist .

添加CoreLocation.framework并导入您的 class.h 文件 -> #import <CoreLocation/CoreLocation.h>然后设置 CLLocationManagerDelegate到你的类(class)。

声明@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委托(delegate)方法

#pragma mark - Location Delegate

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"updated coordinate are %@", [locations lastObject]);
CLLocation *currentLocation = [locations lastObject];
// Your code.....
}

关于ios - 当应用程序处于引导访问模式时,CLLocation 管理器未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30912465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com