在用户使用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)