2017-03-17 1 views
3

사용자가 실수로 알림 수신을 거부하고 나중에 알림을 사용하려는 경우 NSURL을 사용하여 IOS 설정 앱을 앱의 알림 페이지에 열려면 어떻게해야합니까? 알림 허용을 선택 하시겠습니까? 이 설정의 통지를 부분을 열려면 알림 상태 "셀룰러 데이터"설정 앱에서 앱의 알림 설정을 여는 경우

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)) 
+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

, 앱 설정으로 이동 UIApplicationOpenSettingsURLString을 사용`이

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

을 보여줍니다

스위프트 3
관련 문제