2017-03-17 128 views
3

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

+2

' UIApplication.shared.openURL(URL(字符串:UIApplicationOpenSettingsURLString)!)' – duan

+0

[打开从另一个应用程序的设置应用程序]的可能重复(http://stackoverflow.com/questions/5655674/opening-the-settings-app-from -another-app) – duan

+0

matt d你找到解决方案的ID? – user3804063

回答

1

对于斯威夫特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)) 
0

要打开的通知设置的一部分使用

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