Bunu sınıfınıza ekleyin,
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)
}
}
Böyle çağır,
YourClass.showSettingsAlert("App would like to access camera", message: "App would like to access camera desc", onVC: fromViewController, onCancel: {
print("canceled")
})