Reputation: 149
How do I filter the images shown on the PHPickerViewController to those that have been selected under limited access by the user? Or do I need to use a different picker? I've been struggling with this for a few days now. Any help would be appreciated. Thanks in advance.
When user taps the button: 1-5 are automatic
The alert appears with Camera or Photo Library
They choose Photo Library
The authorization alert appears with Select Photo…, Allow Access to All Photos or Don’t Allow
They tap Select Photos = .limited
The presentLimitedLibraryPicker is displayed, for the user to choose the photos thay want to allow and taps Done.
Now I want the picker to appear with a filtered choice of the images the user has just chosen. Seems like this would be automatic too. Not...
This only displays the same picker where the user made the selections for limited access.
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self)
What goes in the .limited case?
var config = PHPickerConfiguration()
config.selectionLimit = 1
config.filter = PHPickerFilter.any(of: [.images, .livePhotos])
let picker_Photo = PHPickerViewController(configuration: config)
picker_Photo.delegate = self
let libCell = UIAction(title: "Photo Library", image: UIImage(systemName: "photo"), identifier: .none, discoverabilityTitle: .none) { (libAction) in
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary)
{
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
switch status
{
case .limited:
DispatchQueue.main.async
{
// PHPhotoLibrary.shared().register(self)
// PHPhotoLibrary.shared().presentLimitedLibraryPicker
self.present(picker_Photo, animated: true, completion: nil)
}
case .authorized:
DispatchQueue.main.async
{
self.present(picker_Photo, animated: true, completion: nil)
}
case .notDetermined:
DispatchQueue.main.async
{
self.present(picker_Photo, animated: true, completion: nil)
}
case .restricted:
self.view.sendConfirmationAlert(theTitle: "Photo Library Restricted",
theMessage: "Photo Library access was previously denied. Please update your Settings to allow access.", buttonTitle: "Ok")
case .denied:
let settingsAlert = UIAlertController(title: "Photo Library Access Denied",
message: "Photo Library access was previously denied. Please update your Settings to allow access.", preferredStyle: .alert)
let settingsAction = UIAlertAction(title: "Go to Settings", style: .default) { ( action ) in
let settingsUrl = URL(string: UIApplication.openSettingsURLString)
UIApplication.shared.open(settingsUrl!, options: [:])
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
DispatchQueue.main.async
{
settingsAlert.addAction(settingsAction)
settingsAlert.addAction(cancelAction)
self.present(settingsAlert, animated: true)
}
default:
return
}
}
}
}
Upvotes: 4
Views: 4806
Reputation: 535890
You are mistaken about what limited access means. It restricts what information you can read and write into the photo library.
But your code does not read from the photo library in the first place. You are saying
config = PHPickerConfiguration()
So this means you have no photo library access at all by way of the picker. You can only get image copies. You therefore do not need any kind of permission to show the picker, and the user limitation makes no difference to you. You can in fact just throw away all your authorization related code; it has no effect. Your picker will work exactly the same without it.
If you needed photo library access by way of the picker, you would have called
https://developer.apple.com/documentation/photokit/phpickerconfiguration/3616114-init
In that case the user limitation would matter to you — when you tried to access an actual PHAsset. But your code never does that. You are asking for a permission you do not need.
Upvotes: 0