Oli*_*ver 1 iphone settings cocoa-touch core-location ios
在设备上进行测试(Iphone 4,IOS 4.2.1),当您使用MapKit/CLLocationManager时,有一个标准对话框,要求用户启用位置设置,并建议按钮进入该设置.
如果单击"确定",则此对话框似乎再也不会出现?
如何让它再次以程序方式显示以帮助用户通过该对话框进入正确的设置视图?
好吧,不可能以编程方式启动标准对话框,要求用户使用位置服务来允许您的应用.这一切都是由iOS完成的.
但是,您始终可以尝试通过实例上的startUpdatingLocation
方法启动位置更新CLLocationManager
.如果禁用了位置服务,您将通过委托获得有关错误情况的通知,然后您可以打开对话框,要求用户进入"设置"并为您的应用启用位置服务...请参阅下面的代码进行过滤kCLErrorDenied
.
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)inManager didFailWithError:(NSError *)inError{
if (inError.code == kCLErrorDenied) {
NSLog(@"Location manager denied access - kCLErrorDenied");
// your code to show UIAlertView telling user to re-enable location services
// for your app so they can benefit from extra functionality offered by app
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,您无法通过应用程序中的URL-scheme启动"设置"应用.
更新:从iOS5.1开始,您不能使用以下方法.
更新:从iOS5开始,您可以从您的应用程序启动设置:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1214 次 |
最近记录: |