App运行过程中需要更改System Setting(swift)

来源:互联网 发布:c图形界面编程 编辑:程序博客网 时间:2024/06/03 10:33
在用户使用App过程中,比如需要开启定位呀,通知呀,可以在应用内直接打开Setting, 而不用进入后台再一步一步来设置,配合iOS9的新特性(左上角的返回按钮)很方便。

这里写图片描述

let alertController = UIAlertController(title: "Sad", message: "Please enable it in Settings", preferredStyle: .Alert)let settingAction  = UIAlertAction(title: "Settings", style: .Default) { (settingAction) -> Void in        if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString){UIApplication.sharedApplication().openURL(appSettings)            }        }    alertController.addAction(settingAction)    let cancelAction = UIAlertAction(title: "Cancel",style: .Cancel,handler: nil)    alertController.addAction(cancelAction)    presentViewController(alertController, animated: true, completion: nil)
0 0