Skip to content

Conversation

@natecraft1
Copy link

Issue

Setting custom fetchResults prior to obtaining Photos permission from the user results in null AssetCollections, and thus will present an empty ImagePickerController the first time it is presented.

For instance

let imagePickerVC = ImagePickerController()
imagePickerVC.settings.fetch.album.fetchResults = [PHAssetCollection.fetchAssetCollection(with: .album, subtype: .albumRegular, options: PHFetchOptions())]
imagePickerVC.presentImagePicker(...

will have the effect of presenting an empty picker the first time after permissions are first granted.

Proposed solution
Defer the access of the fetchResults settings by using a function rather than a var.

Note
There are other ways of solving this, such as adding an onAuthorization closure to the presentImagePicker call and allowing settings to be passed in there.

public lazy var fetchResults: [PHFetchResult<PHAssetCollection>] = [
PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: options),
]
public lazy var fetchResults: () -> [PHFetchResult<PHAssetCollection>] = { [options] in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public lazy var fetchResults: () -> [PHFetchResult<PHAssetCollection>] = { [options] in
public lazy var fetchResults: () -> [PHFetchResult<PHAssetCollection>] = {

PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: options),
]
public lazy var fetchResults: () -> [PHFetchResult<PHAssetCollection>] = { [options] in
return [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return [
[

@mikaoj
Copy link
Owner

mikaoj commented Dec 19, 2021

Sure makes sense. Wouldn't some of the examples also need to be updated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants