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

标签 ios objective-c cllocationmanager

我目前正在开发基于位置的 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/

相关文章:

iphone - 在 iPhone 应用程序的 map 上通过适当的图标显示酒店(和附近的地方)

ios - iOS 中的 FirebaseInstanceId 是什么?

iphone - 手势识别器 : shouldReceiveTouch: not getting called

objective-c - Node.js bodyparser 无法准备好 AFNetworking POST 数组

ios - Swift 4 设置包,获取默认值

iOS UITableViewCell 动画延迟加载不起作用

ios - 在 iOS 中显示相同文本的多个信息窗口

iphone 当前位置不显示

ios - 如何从iOS中的经度和纬度获取ZipCode?

ios - 类型为 'required' 的委托(delegate)