gpt4 book ai didi

iphone - locationManager didFailWithError 重复调用

转载 作者:行者123 更新时间:2023-11-28 18:41:49 44 4
gpt4 key购买 nike

当位置管理器无法找到当前位置时,我正在显示 alertViews。我是这样做的

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {

[manager stopUpdatingLocation];

switch([error code])
{
case kCLErrorNetwork: // general, network-related error
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please check your network connection or that you are not in airplane mode" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
break;
case kCLErrorDenied:{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"User has denied to use current Location " delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
break;
default:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Unknown network error" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
break;
}

}

我的问题是locationManager didFailWithError 方法被重复调用。所以我的 alertviews 反复显示。

我该如何解决这个问题?

最佳答案

Apple 文档指出:

If the location service is unable to retrieve a location right away, it reports a kCLErrorLocationUnknown error and keeps trying. In such a situation, you can simply ignore the error and wait for a new event.

If the user denies your application’s use of the location service, this method reports a kCLErrorDenied error. Upon receiving such an error, you should stop the location service.

因此您可能会跳过某些停止更新并显示警报的情况,尤其是默认情况。

关于iphone - locationManager didFailWithError 重复调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10207138/

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