gpt4 book ai didi

iphone - 在 iPhone 中允许定位服务

转载 作者:行者123 更新时间:2023-11-29 11:05:11 25 4
gpt4 key购买 nike

我正在制作一个需要用户位置的应用程序。我正在使用这段代码 -

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;

如果用户不允许那里的位置,那么下次当用户打开应用程序时,我将使用此代码来允许用户的位置 -

 if([CLLocationManager locationServicesEnabled] && 
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
NSLog(@"enable");
}
else {
NSLog(@"disable");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
}

但这在 iOS SDK 5.1 中不起作用。所以我希望每次当应用程序进入前台时,如果定位服务被禁用,那么如何给出允许定位服务的弹出窗口。

最佳答案

设置应用程序 URL 方案不再可用,您只需向用户显示一个 UIAlertView 或以模态方式显示一个 UIViewController 告诉用户打开您的应用程序的位置服务。

您不能真正强制允许位置对话框,它只会在第一次弹出。

关于iphone - 在 iPhone 中允许定位服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13971865/

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