gpt4 book ai didi

iphone - 如何知道CLLocationManager用户触摸了哪个警报按钮?

转载 作者:行者123 更新时间:2023-12-03 20:21:02 24 4
gpt4 key购买 nike

CLLocationManager 提示警报

"App name" Would you like to use your location

它提供两个按钮,确定不允许。如何知道用户选择了哪个按钮?

最佳答案

当您单击“不允许”按钮时

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
将在调用时出现 kCLAuthorizationStatusDenied 异常。你可以在里面写你的内容。

另请参阅:

kCLAuthorizationStatusNotDetermined = 0, // User has not yet made a choice with regards to this application
kCLAuthorizationStatusRestricted, // This application is not authorized to use location services. Due
// to active restrictions on location services, the user cannot change
// this status, and may not have personally denied authorization
kCLAuthorizationStatusDenied, // User has explicitly denied authorization for this application, or
// location services are disabled in Settings
kCLAuthorizationStatusAuthorized // User has authorized this application to use location services

示例:

如果用户点击允许,则

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{
[self refreshYourView];
}

如果点击不允许

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{
if ([error code]== kCLAuthorizationStatusDenied)
{
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"User has clicked don't allow button." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

}
}

编辑

替代:您可以显示一条警报,要求用户通过从设置启用位置服务来允许位置访问。

您可以在 iOS 5.0 及更高版本上使用此功能:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];

在您的应用中打开“设置”应用。

关于iphone - 如何知道CLLocationManager用户触摸了哪个警报按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9109316/

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