Skip to content

Commit c1f7704

Browse files
author
Emilio Pavia
committed
Adopt new PHPhotoLibrary APIs in iOS 14
1 parent 8ace23c commit c1f7704

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

ScienceJournal/UI/PhotoLibraryDataSource.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,29 @@ class PhotoLibraryDataSource: NSObject, PHPhotoLibraryChangeObserver {
9090

9191
/// The permissions state of the capturer.
9292
var isPhotoLibraryPermissionGranted: Bool {
93-
let authStatus = PHPhotoLibrary.authorizationStatus()
93+
let authStatus: PHAuthorizationStatus
94+
if #available(iOS 14, *) {
95+
authStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite)
96+
} else {
97+
authStatus = PHPhotoLibrary.authorizationStatus()
98+
}
9499
switch authStatus {
95100
case .denied, .restricted: return false
96101
case .authorized, .limited: return true
97102
case .notDetermined:
98-
// Prompt user for the permission to use the camera.
99-
PHPhotoLibrary.requestAuthorization({ (status) in
103+
let handler: (PHAuthorizationStatus) -> Void = { status in
100104
DispatchQueue.main.sync {
101105
let granted = status == .authorized
102106
self.delegate?.photoLibraryDataSourcePermissionsDidChange(accessGranted: granted)
103107
}
104-
})
108+
}
109+
110+
// Prompt user for the permission to use the camera.
111+
if #available(iOS 14, *) {
112+
PHPhotoLibrary.requestAuthorization(for: .readWrite, handler: handler)
113+
} else {
114+
PHPhotoLibrary.requestAuthorization(handler)
115+
}
105116
return false
106117
@unknown default: return false
107118
}

0 commit comments

Comments
 (0)