使用此代码。可能会有所帮助。
override func viewDidAppear(animated: Bool) {
var alertController = UIAlertController (title: "Title", message: "Go to Settings?", preferredStyle: .Alert)
var settingsAction = UIAlertAction(title: "Settings", style: .Default) { (_) -> Void in
let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
if let url = settingsUrl {
UIApplication.sharedApplication().openURL(url)
}
}
var cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)
alertController.addAction(settingsAction)
alertController.addAction(cancelAction)
presentViewController(alertController, animated: true, completion: nil);
}
请注意UIApplicationOpenSettingsURLString
仅在 iOS8.0 和之后可用,因此如果您的应用程序应该支持 iOS7,您必须检查常量的可用性(或者如果使用 Swift 2.0,请使用#availability
关键字)。