개발/아이오에스

swift]앱에서 디바이스 환경설정 - 해당 앱 알림 설정 창 화면에 띄우는 방법

dev.jake 2021. 8. 26. 11:32

   UNUserNotificationCenter.current().getNotificationSettings { (settings) in

                guard settings.authorizationStatus == .authorized else{

                    let alert = UIAlertController(title: "알림", message: "기기 내 [설정]>[앱 이름]>[알림]에서\n알림을 허용해주세요.", preferredStyle: .alert)

                    alert.addAction(UIAlertAction(title: "취소", style: .cancel, handler: nil))

                    alert.addAction(UIAlertAction(title: "확인", style: .default, handler: { _ in

                        DispatchQueue.main.async {

                            let settingUrl = NSURL(string: UIApplication.openSettingsURLString)!

                            if UIApplication.shared.canOpenURL(settingUrl as URL){

                                UIApplication.shared.open(settingUrl as URL, options: self.convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: { (istrue) in

                                })

                            }

                        }

                    }))

                    self.present(alert, animated: true)

                    return

                }
}

 

 func convertToUIApplicationOpenExternalURLOptionsKeyDictionary(_ input: [String: Any]) -> [UIApplication.OpenExternalURLOptionsKey: Any] {

        return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIApplication.OpenExternalURLOptionsKey(rawValue: key), value)})

    }