2017-03-17 126 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)