iOS Swift/개발 이모저모
[권한]아이폰 앨범 접근 권한 확인하기
호두빵
2022. 12. 21. 17:59

func albumAccess() -> Bool{
let status = PHPhotoLibrary.authorizationStatus()
PHPhotoLibrary.requestAuthorization{status in
switch status {
case .authorized, .limited :
print("album access allowed")
case .denied, .restricted :
print("album access not allowed")
case .notDetermined :
print("album access not determined")
@unknown default:
print("albmum access default")
}
}
if status == PHAuthorizationStatus.authorized {
return true
} else {
return false
}
}
애플은 개인정보 보호를 중요하게 생각하는 만큼, 개발자가 특정 데이터를 가져와서 쓰고자 할 때 그 데이터를 왜 쓰려고 하는지, 권한을 왜 요구하는지를 상세하게 요구하는 편입니다. 따라서 앱에서 어떠한 이미지를 쓰고자 할 때, 무작정 가져와서 쓰는 것보다, 먼저 사용자에게 나의 앱에게 권한을 줄 것인지를 확인하는 것이 좋습니다. albumAccess라는 function을 생성하여서, PHPhotoLibrary의 권한요청(requestAuthorization)을 통해 권한을 부여받게 되면 Boolean 값으로 true를 return하여 오직 true값일때만 다음 작업을 진행하게끔 합니다.