앨범 접근 권한을 거부한 유저에게 '권한 설정' 페이지로 이동할 수 있도록 alert
창을 보여주는 상황이다.
SwiftUI에서 View를 사용하지 않고 프로그램 상으로 UIAlertController
를 띄우는 방법이 필요하다.
- UIAlertController의
title
,message
설정- controller에
action
추가 (ex: 취소, 설정)let viewController = UIApplication.shared.windows.first!.rootViewController! viewController.present(alert, animated: true, completion: nil)
func AuthSettingOpen(AuthString: String) {
if let AppName = Bundle.main.infoDictionary!["CFBundleName"] as? String {
let message = "\(AppName)이 \(AuthString) 접근 허용되어 있지않습니다. \r\n 설정화면으로 가시겠습니까?"
let alert = UIAlertController(title: "설정", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "취소", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "설정", style: .default, handler: { _ in
if let settingsURL = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(settingsURL)
}
}))
let viewController = UIApplication.shared.windows.first!.rootViewController!
viewController.present(alert, animated: true, completion: nil)
}
}