好吧,我知道关于它有很多问题,但它们都是很久以前的事了。

所以。我知道这是可能的,因为地图应用程序做到了。

在地图应用程序中,如果我关闭这个应用程序的本地化,它会给我发送一条消息,如果我按ok,“设置应用程序”就会打开。 我的问题是,这怎么可能呢? 如何从我自己的应用程序打开“设置应用程序”?

基本上我需要做同样的事情,如果用户关闭了我的应用程序的位置,那么我就会给他显示一条信息,上面写着将打开“设置应用程序”


当前回答

斯威夫特4

我更喜欢以更安全的方式打开设置,

if let settingUrl = URL(string:UIApplicationOpenSettingsURLString) {

    UIApplication.shared.open(settingUrl)
}
else {
    print("Setting URL invalid")
}

其他回答

斯威夫特4

我更喜欢以更安全的方式打开设置,

if let settingUrl = URL(string:UIApplicationOpenSettingsURLString) {

    UIApplication.shared.open(settingUrl)
}
else {
    print("Setting URL invalid")
}

斯威夫特3:

guard let url = URL(string: UIApplicationOpenSettingsURLString) else {return}
if #available(iOS 10.0, *) {
  UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
  // Fallback on earlier versions
  UIApplication.shared.openURL(url)
}

把这个加到你的课上,

 public class func showSettingsAlert(title:String,message:String,onVC viewController:UIViewController,onCancel:(()->())?){
            YourClass.show2ButtonsAlert(onVC: viewController, title: title, message: message, button1Title: "Settings", button2Title: "Cancel", onButton1Click: {
                if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString){
                    UIApplication.sharedApplication().openURL(settingsURL)
                }
                }, onButton2Click: {
                    onCancel?()
            })
        }

 public class func show2ButtonsAlert(onVC viewController:UIViewController,title:String,message:String,button1Title:String,button2Title:String,onButton1Click:(()->())?,onButton2Click:(()->())?){
            dispatch_async(dispatch_get_main_queue()) {
                let alert : UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)

                alert.addAction(UIAlertAction(title: button1Title, style:.Default, handler: { (action:UIAlertAction) in
                    onButton1Click?()
                }))

                alert.addAction(UIAlertAction(title: button2Title, style:.Default, handler: { (action:UIAlertAction) in
                    onButton2Click?()
                }))

                viewController.presentViewController(alert, animated: true, completion: nil)
            }
        }

像这样调用,

YourClass.showSettingsAlert("App would like to access camera", message: "App would like to access camera desc", onVC: fromViewController, onCancel: {
  print("canceled")
})

是的! !你可以启动设备设置界面,我已经在iOS 9.2上测试过了

步骤1。我们需要添加URL方案

去项目设置——>信息——> URL类型——>添加新的URL方案

步骤2。通过编程启动设置感谢@davidcann

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

此外,我们还可以通过使用适当的名称来启动音乐、位置等子屏幕

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=MUSIC"]];

请看亨利·诺马克分享的完整名单


更新:

根据评论,每个人都想知道我的申请提交状态改变后会发生什么?

是的! !我获得了成功的更新提交和应用程序可在商店没有任何抱怨。

确认一下, 我今天早上刚下载并禁用了位置服务,然后启动了应用程序,它要求我获得位置权限,然后我的警报弹出在那里发送给我设置->位置服务页面->启用->就是这样!!

(注意:! 你的应用可能会被拒绝……如果你使用这种方法,即使它被批准了,在将来的版本中也可能会被拒绝

由于openURL(_::)在iOS 10.0之后已被弃用,请使用open(_:options:completionHandler:)代替。

if let settingsUrl = URL(string: UIApplication.openSettingsURLString)  {
        UIApplication.shared.open(settingsUrl, options: [:]) { completed in
             if !completed {
                 print("Failed opening")
             }
        }
}