I’m utilizing the brand new PHPickerViewController & Delegate on iOS15+. The way in which I perceive it, I assumed I’d not must implement something past the delegate for the ‘restricted images’ mode because it runs out of course of. Nevertheless, it looks like the didFinishPicking methodology within the delegate is returning images I am unable to entry, with out prompting the consumer to present me entry.
Right here is how I present the picture picker:
var configuration = PHPickerConfiguration(photoLibrary: .shared())
// Set the filter sort to photographs just for now
configuration.filter = PHPickerFilter.any(of: [.images])
// Set the mode to keep away from transcoding, if doable, in case your app helps arbitrary picture/video encodings.
configuration.preferredAssetRepresentationMode = .suitable
// Set the choice habits to respect the consumer’s choice order.
configuration.choice = .ordered
// Set the choice restrict to allow multiselection.
configuration.selectionLimit = 8
// Set the preselected asset identifiers with the identifiers that the app tracks.
configuration.preselectedAssetIdentifiers = self.selectedAssetIdentifiers
// Present it
let picker = PHPickerViewController(configuration: configuration)
picker.delegate = self
(UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController?.current(picker, animated: true, completion: nil)
And right here is my delegate:
func picker(_ picker: PHPickerViewController, didFinishPicking outcomes: [PHPickerResult]) {
dismiss(animated: true)
let existingSelection = self.choice
var newSelection = [String: PHPickerResult]()
for lead to outcomes {
let identifier = end result.assetIdentifier!
newSelection[identifier] = existingSelection[identifier] ?? end result
}
// Monitor the choice in case the consumer deselects it later.
_selection = newSelection
selectedAssetIdentifiers = outcomes.map(.assetIdentifier!)
selectedAssetIdentifierIterator = selectedAssetIdentifiers.makeIterator()
// Convert and cargo into the attachment supervisor
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: outcomes.compactMap(.assetIdentifier), choices: nil)
// Loop by way of the objects within the fetch end result utilizing enumerateObjects
fetchResult.enumerateObjects { (asset, index, cease) in
// Do one thing with 'asset' and 'index'
let choices = PHImageRequestOptions()
choices.deliveryMode = .highQualityFormat
choices.resizeMode = .quick
choices.isNetworkAccessAllowed = true
// Ideally we deal with this higher within the UI with out freezing.
choices.isSynchronous = true
let picture = asset.picture(targetSize: PHImageManagerMaximumSize, contentMode: PHImageContentMode.default, choices: choices)
let dealt with = self.attachmentManager.handleInput(of: picture)
if !dealt with {
// throw error
}
}
}
Within the restricted picture mode, it looks like my didFinishPicking delegate methodology isn’t known as—or at the least by no means known as in conditions the place the consumer has chosen a photograph from their library that they didn’t give me permission with the primary time spherical.
Are there different strategies I have to implement to help this privateness centered mode?