我想要触发这个警告:
Turn On Location Services to allow maps to determine your location
我需要像“地图”应用程序一样同时具有“设置”和“取消”按钮。
“设置”应该打开设置->通用->位置服务
我找不到打开设置页面的方法。
你能帮帮我吗?
谢谢
我想要触发这个警告:
Turn On Location Services to allow maps to determine your location
我需要像“地图”应用程序一样同时具有“设置”和“取消”按钮。
“设置”应该打开设置->通用->位置服务
我找不到打开设置页面的方法。
你能帮帮我吗?
谢谢
创建警报非常简单,它只是一个(仿)模态UIView。
然而,程序上无法以编程方式打开设置应用程序,至少不使用私有方法将会防止您的应用在应用商店中获得批准。
在iOS 8中,你不能打开特定的设置页面,比如“通用”、“位置”等,但是你可以打开设置页面。
- (void)openSettings
{
BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
if (canOpenSettings)
{
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
}
这是不可能单独完成的。然而,如果您的应用程序需要访问位置服务,则操作系统会为您呈现如下所示的对话框。
编辑:Brant在下面提到,“可以通过设置CLLocationManager的purpose属性的值来自定义消息。”
CLLocationManager
上设置purpose
属性的值来自定义消息。 - Brant Bobbypurpose
在iOS 6.0中已被弃用 - http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/CLLocationManager/purpose - user427969Swift 2.0 版本:
func showLocationSettingAlert() {
let alertController = UIAlertController(
title: "Location Access Disabled",
message: "Location settings",
preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alertController.addAction(cancelAction)
let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in
if let url = NSURL(string:UIApplicationOpenSettingsURLString) {
UIApplication.sharedApplication().openURL(url)
}
}
alertController.addAction(openAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
这不是你要添加的内容。当应用程序想要使用位置服务,但在设置中它被关闭时,就会出现该屏幕。
推送通知也会发生同样的情况。
正如其他人所说,如果你想让你的应用程序在App Store上架,那么你不能以编程方式打开设置应用程序。
如果你的应用程序支持并使用了像位置服务这样的特定功能,那么这个弹出窗口会在启动应用程序时自动生成。
你可以在参考库中找到有关此服务的更多信息:https://developer.apple.com/library/ios/navigation/#section=Frameworks&topic=CoreLocation