Is there any way to preserve the list order a user has arranged all of their albums in the Photos app? I've been trying to fix this all day, and I can't seem to figure out what I'm missing to preserve the order for displaying in my app.
I would like to preserve the order because a user can rearrange their albums in the Photos app, so I want my UI to match the list order.
Code I'm using to set up the list:
PHFetchResult *smartAlbumFetchResult = [PHAssetCollection fetchAssetCollectionsWithType:
PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
PHFetchResult *albumFetchResult = [PHAssetCollection fetchAssetCollectionsWithType:
PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
NSArray *collectionFetches = @[smartAlbumFetchResult, albumFetchResult];
NSMutableArray *albumArray = [NSMutableArray new];
for (PHFetchResult *newFetch in collectionFetches)
{
for (PHAssetCollection *sub in newFetch)
{
[albumArray addObject:sub];
// Other setup omitted
}
}
Sorry, but I don't think it's possible actually (I hope in some upgrades).
In fact, it is possible to use PHFetchOptions to sort asset collections, but PhotoKit supports only a restricted set of keys for the predicate and sortDescriptors properties (see PHFetchOptions) and between these I can't see a key for the the list order a user has arranged in the Photos app.