티스토리 뷰

Why ?


  • 자주 사용하지만 프로젝트에서 한번씩만 사용해서 항상 구글링을 하길래 그냥 통으로 정리해두려고 한다.

How ?


// Request 코드

func requestCamera() {
    AVCaptureDevice.requestAccess(for: .video) { isAccess in
        print(isAccess ? "카메라 권한 허용" : "카메라 권한 거부")
    }
}

func requestPhoto() {
    PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
        switch status{
        case .authorized:
            print("Album: 권한 허용")
        case .denied:
            print("Album: 권한 거부")
        case .restricted, .notDetermined:
            print("Album: 선택하지 않음")
        default:
            break
        }
    }
}

func requestLocation() {
    CLLocationManager().requestWhenInUseAuthorization()
}

func requestNotification() {
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { isAccess, error in
        print(isAccess ? "알림 권한 허용" : "알림 권한 거부")
    }
}
// info.plist

Privacy - Camera Usage Description
Privacy - Photo Library Usage Description
Privacy - Location When In Use Usage Description
  • 위치 권한은 여러가지가 있으니 상황에 맞게 사용해야한다.

'iOS > iOS' 카테고리의 다른 글

[iOS] CocoaPods vs Carthage vs SPM  (0) 2023.01.04
[iOS] 프레임워크와 라이브러리  (0) 2023.01.04
[iOS] 다크모드 미 지원  (0) 2022.06.15
[WWDC2022] Platforms State of the Union  (0) 2022.06.09
[iOS] OCR(3) - Google MLKit  (0) 2022.05.22
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함