Nil*_*nch 5 iphone objective-c core-location permission-denied cllocationmanager
我一直在努力处理我的iPhone应用程序的位置服务请求.如果用户说"不允许",我就会陷入"我的应用需要位置服务以便工作"...
所有重新申请位置服务的尝试都没有结果,这里有几个堆栈可以证明.
然后我读到重新启用位置服务的唯一方法是使用以下方法将用户重定向到位置服务设置:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
Run Code Online (Sandbox Code Playgroud)
但即使这似乎也不起作用(iPhone 4和4S,均为5.1)
除了告诉用户去偏好然后引导他通过之外,真的没有别的办法吗?对我来说,这似乎很笨拙.
如果用户关闭了定位服务,则没有其他方法可以告诉用户再次打开它们。
您可以尝试重定向,但这只能在 iOS 5.0 上进行。所以你可以这样做:
NSURL *prefsURL = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
if ([[UIApplication sharedApplication] canOpenURL:prefsURL]) {
[[UIApplication sharedApplication] openURL:prefsURL];
} else {
// Can't redirect user to settings, display alert view
UIAlertView *alertView = ....
}
Run Code Online (Sandbox Code Playgroud)