2017-03-17 7 views
3

ユーザが誤って通知を受け取ることを拒否し、後で通知をしたい場合は、NSURLを使用してIOS設定アプリを自分のアプリの通知ページに開く方法[通知を許可する]を選択します。設定の通知を開くにはスウィフト3、それは通知の状態を示しており、アプリの設定に移動しUIApplicationOpenSettingsURLStringを使用し、「携帯電話のデータ」については設定アプリでアプリの通知設定を開く

+2

を使用しますUIApplication.shared.openURL(URL(string:UIApplicationOpenSettingsURLString)!) ' – duan

+0

[別のアプリから設定アプリを開く]の複製が可能です。(http://stackoverflow.com/questions/5655674/opening-the-settings-app-from -another-app) – duan

+0

マットdあなたが解決策を見つけたのですか? – user3804063

答えて

1

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) 
関連する問題