当应用首次尝试获取用户位置时,会提示他们“想要使用您当前的位置”,他们可以点击“不允许”或“确定”。有没有办法找出用户是否已经确定或不允许?我正在尝试让MKMapView显示用户当前位置,但我想根据用户选择采取不同的操作。
通常你会认为有一个代表来获取这些信息,但似乎没有。
提前感谢您的帮助。
答案 0 :(得分:16)
您获取用户位置的第一个电话将失败,并显示一条错误消息,告知您用户已拒绝了位置服务。您的CLLocationManagerDelegate
方法didFailWithError
将被调用,如下所示。 (常量在CLError.h
)中定义
- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError
{
switch([anError code])
{
case kCLErrorLocationUnknown: // location is currently unknown, but CL will keep trying
break;
case kCLErrorDenied: // CL access has been denied (eg, user declined location use)
message = @"Sorry, flook has to know your location in order to work. You'll be able to see some cards but not find them nearby";
break;
case kCLErrorNetwork: // general, network-related error
message = @"Flook can't find you - please check your network connection or that you are not in airplane mode";
}
}