在设置应用中打开应用的通知设置

如果用户可能意外拒绝接收通知并希望稍后再发送通知,我如何使用NSURL将IOS设置应用程序打开到我的应用程序的通知页面,在那里他们可以选择允许通知?

对于Swift 3,使用UIApplicationOpenSettingsURLString转到应用程序的设置,其中显示通知状态和“蜂窝数据”

 let settingsButton = NSLocalizedString("Settings", comment: "") let cancelButton = NSLocalizedString("Cancel", comment: "") let message = NSLocalizedString("Your need to give a permission from notification settings.", comment: "") let goToSettingsAlert = UIAlertController(title: "", message: message, preferredStyle: UIAlertControllerStyle.alert) goToSettingsAlert.addAction(UIAlertAction(title: settingsButton, style: .destructive, handler: { (action: UIAlertAction) in DispatchQueue.main.async { guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else { return } if UIApplication.shared.canOpenURL(settingsUrl) { if #available(iOS 10.0, *) { UIApplication.shared.open(settingsUrl, completionHandler: { (success) in print("Settings opened: \(success)") // Prints true }) } else { UIApplication.shared.openURL(settingsUrl as URL) } } } })) logoutUserAlert.addAction(UIAlertAction(title: cancelButton, style: .cancel, handler: nil)) 

要打开通知部分设置,请使用此选项

 UIApplication.shared.open(URL(string:"App-Prefs:root=NOTIFICATIONS_ID")!, options: [:], completionHandler: nil)