Reputation: 33
In WWDC2020, new PHPickerViewController and new PHPhotoLibrary.authorizationStatus(limited) were introduced. But I got below issue:
when user tapped a button to show the apple's multiple images picker and display the requestAuthorization as code:
let requiredAccessLevel: PHAccessLevel = .readWrite
PHPhotoLibrary.requestAuthorization(for: requiredAccessLevel) { (authorizationStatus) in
switch authorizationStatus {
case .authorized:
DispatchQueue.main.async {
self.presentImagePicker()
}
case .limited:
DispatchQueue.main.async {
self.presentImagePicker()
}
default:
break
}
}
self.presentImagePicker() functions:
func presentImagePicker() {
var configuration = PHPickerConfiguration(photoLibrary: .shared())
configuration.filter = .images
configuration.selectionLimit = self.imageCountMax - self.images.count
let picker = PHPickerViewController(configuration: configuration)
picker.delegate = self
let accessLevel: PHAccessLevel = .readWrite
let authorizationStatus = PHPhotoLibrary.authorizationStatus(for: accessLevel)
switch authorizationStatus {
case .authorized:
DispatchQueue.main.async {
self.present(picker, animated: true)
}
case .limited:
DispatchQueue.main.async {
// Here I don't know how to display only limited photo library to users (after user has selected some photos through the limited access)
}
default:
break
}
}
my issue: please see code 2, case .limited: DispatchQueue.main.async { }, I think I should put the limited photo library in this block, but I don't know how to display only limited photo library to users.
Upvotes: 2
Views: 3071
Reputation: 176
You can use this PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self)
method into .limited
DispatchQueue.main.async {
// Here I don't know how to display only limited photo library to users (after user has selected some photos through the limited access)
PHPhotoLibrary.shared().register(self)
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self)
}
and after that you have to use the delegate method for get the updated images.
func photoLibraryDidChange(_ changeInstance: PHChange) {
let fetchOptions = PHFetchOptions()
self.allPhotos = PHAsset.fetchAssets(with: .image, options: fetchOptions)
}
Upvotes: 1