[Swift] 앱에서 앱 설정으로 이동
2024. 8. 6. 22:31
if let url = URL(string: UIApplication.openSettingsURLString){
UIApplication.shared.open(url)
}
응용
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
'iOS > Swift' 카테고리의 다른 글
[iOS/WKWebKit] WKWebView에 httpCookie 설정 (1) | 2024.09.08 |
---|---|
[iOS/WebKit] Completion handler passed to [webView:decidePolicyForNavigationAction:decisionHandler:] was called more than once 오류 (1) | 2024.06.09 |
[Swift] DispatchQueue (3) - DispatchGroup (0) | 2024.04.20 |
[iOS] HTTP Cookie (0) | 2024.03.24 |
[iOS] WKScriptMessageHandler (0) | 2024.03.16 |