[Swift] 앱에서 앱 설정으로 이동

2024. 8. 6. 22:31
 

openSettingsURLString | Apple Developer Documentation

The URL string you use to deep link to your app’s custom settings in the Settings app.

developer.apple.com

if let url = URL(string: UIApplication.openSettingsURLString){
    UIApplication.shared.open(url)
}

 

응용

 

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

UNUserNotificationCenter.current().getNotificationSettings { (settings) in guard settings.authorizationStatus == .authorized else{ let alert = UIAlertController(title: "알림", message: "기기 내 [설정]>[앱 이름]>[알림]에서\n알림을 허용해

dev-geeyong.tistory.com

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)})
}
728x90

BELATED ARTICLES

more