반응형
1. 시작
간단히, App Settings에 접근하는 코드를 알아 봅시다.
<swift>
private func presentAppSettingsAlert() {
let alertController = UIAlertController(
title: "위치 접근 요청",
message: "위치 정보를 얻을 수 없습니다. 위치 권한을 '항상 허용'으로 변경해 주세요.",
preferredStyle: .alert
)
let action = UIAlertAction(
title: "설정창 이동",
style: .default,
handler: goToAppSettings
)
alertController.addAction(action)
self.present(alertController, animated: true)
}
private func goToAppSettings(_ sender: UIAlertAction) {
guard let settingURL = URL(string: UIApplication.openSettingsURLString) else { return }
if UIApplication.shared.canOpenURL(settingURL) {
UIApplication.shared.open(settingURL)
}
}
반응형
'TIP' 카테고리의 다른 글
[Swift/ TIP] subscript 활용 (깔끔하게 모델에 접근) (2) | 2023.11.21 |
---|---|
[Swift/ TIP] 앱 이름 변경하기 (+Localization) (0) | 2023.07.21 |
[Swift/ TIP] 앱 추적 투명성 권한 요청 (App Tracking Transparency) (0) | 2023.07.21 |
[Swift/ Tip] 스크린의 크기를 구해보자 (UIScreen.main is deprecated) (0) | 2023.07.18 |
[Swift/ Tip] 한 버튼에서 2가지 동작을 사용해보자 (0) | 2023.07.15 |