我在查找当前位置时遇到了一些困难,在使用 CLLocationManager 时,它会要求一个通知,例如“您想使用您当前的位置”吗?对。其中有两个选项名为:1.OK 2.Dont Allow。是否可以为这两个按钮编写自定义操作...如果有人有任何想法可以做到这一点并与此相关,那么对我来说将非常有用..
提前致谢...
我在查找当前位置时遇到了一些困难,在使用 CLLocationManager 时,它会要求一个通知,例如“您想使用您当前的位置”吗?对。其中有两个选项名为:1.OK 2.Dont Allow。是否可以为这两个按钮编写自定义操作...如果有人有任何想法可以做到这一点并与此相关,那么对我来说将非常有用..
提前致谢...
制作这样的方法并将其附加到您的按钮或从 viewDidLoad 调用它
-(void) showLocation
{
// put an alerview to ask user for allow/disallow
}
// 在alerView 委托方法中,再次是按钮启用用户当前位置
我认为您不能覆盖此警报的操作。但是,您可以实现 CLLocationManager 的委托方法
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error;
在那里,您可以了解用户是否为您的应用启用了定位服务。
这是上述方法的实现示例
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
[self.locationManager stopUpdatingLocation];
switch([error code]) {
case kCLErrorDenied:
//User has not enabled location services for this app.
break;
case kCLErrorLocationUnknown:
//location could not be found
break;
default:
//some other issue
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"An error title"
message:@"An error message"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}