gpt4 book ai didi

ios - Clocationmanager Didupdatelocation 委托(delegate)在没有互联网的情况下不会被调用

转载 作者:行者123 更新时间:2023-11-29 12:23:57 25 4
gpt4 key购买 nike

我目前正在开发基于位置的 iOS 应用程序。我正在使用 diduplatelocation 委托(delegate)方法来显示用户的当前位置。当我将我的设备连接到互联网时,它工作正常。但是当我断开互联网时,它的行为很奇怪并且 didupdatelocation 没有被进一步调用。请给出解决方案。已编辑,包含代码详细信息

- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
locationManager.delegate = self; // we set the delegate of locationManager to self.
locationManager.desiredAccuracy = kCLLocationAccuracyBest; // setting the accuracy

[locationManager startUpdatingLocation]; //requesting location updates
}

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"There was an error retrieving your location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[errorAlert show];
NSLog(@"Error: %@",error.description);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *crnLoc = [locations lastObject];
latitude.text = [NSString stringWithFormat:@"%.8f",crnLoc.coordinate.latitude];
longitude.text = [NSString stringWithFormat:@"%.8f",crnLoc.coordinate.longitude];
altitude.text = [NSString stringWithFormat:@"%.0f m",crnLoc.altitude];
speed.text = [NSString stringWithFormat:@"%.1f m/s", crnLoc.speed];
}

最佳答案

@ANSHAD 根据您的评论,如果您使用的是没有 GPS 的旧 iPad,则获取位置数据的唯一方法是使用 WiFi,因此如果您关闭 WiFi,您将无法获得位置更新。如果你想要没有 WiFi 的 GPS,你可以购买一个外部 GPS 模块 see here

关于ios - Clocationmanager Didupdatelocation 委托(delegate)在没有互联网的情况下不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29821869/

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