Fotokit saves the list of albums of albums of users

Is there a way to keep the order in the list that the user has ordered with all their albums in the Photos app? I have been trying to fix this all day, and I can't figure out what I am missing to keep the display order in my application.

I would like to save the order because the user can change their albums in the Photos application, so I want my user interface to follow the order of the list.

The code I use to create the list is:

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 } } 
+8
ios objective-c photokit photosframework
source share
2 answers

Sorry, but I do not think that this is actually possible (I hope in some updates).
In fact, PHFetchOptions can be used to sort collections of assets, but PhotoKit only supports a limited set of keys for predicate properties and sortDescriptors (see PHFetchOptions ), and between them I do not see the key for ordering the list that the user ordered in the Photos application.

+2
source share

Can you create a property in the PHAssetCollection class that takes order into account? That way you can show them based on the property.

A very simple example: if a class contains a number from 1 - n, based on this number, do you know which class / photo will be displayed? (or sort them based on this property, and you can just loop it after sorting.)

@Edit A simple example:

In the PHAssetCollection class in the .h file, you declare a property.

 @property (retain, nonatomic) NSInteger id; 

In the PHAssetCollection class in the .m file, you can fill it with the initialization method. If you want to use it in a .m file, you need to synthesize it. You can refuse the course to fill out, as always and whenever you want, it depends on your needs. I can imagine that they get a standard identifier, and when a user drags a photo, he sets a new identifier on it.

You can sort your list based on the following: implement the comparison method and call the comparison function:

 //Implement - (NSComparisonResult)compare:(PHAssetCollection *)otherPhoto{ return [self.id compare:otherPhoto.id]; } //Call method NSMutableArray *sortedArray; sortedArray = [sub sortedArrayUsingSelector:@selector(compare:)]; 

There are many ways to do this. Another tricky one is keeping track of the order in the background and not changing the identifier every time you change an order. When ApplicationWillTerminate or ApplicationDidEnterBackground is called, you change the identifier of the photos based on the order of the photos. This way, you only need to change the identifier once, and this will save you some performance.

0
source share

All Articles