I am trying to reproduce the native iOS8 photopicker using Photos framework. I got a problem with the sorting.
Lets say I do following:
In the native photopicker:
creationDate
In my app I do following:
PHFetchOptions *options = [PHFetchOptions new];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", PHAssetMediaTypeImage];
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:self.assetCollection options:options];
I sort in creationDate
and get following result:
creationDate
Then I change my query so instead of sorting on creationDate
, I sort on modificationDate
. I get following result:
creationDate
So it seeme Apple change modificationDate
on favourite action and probably also on other kind of actions and this mess up the sorting of the photos.
How is it possible to get exactly the sorting Apple use in its native app? Maybe some clever use of NSSortDescriptor
?
I just found out that to copy the exact behaviour of the native photopicker the sollution was to remove my custom sortDescriptior
and just use the PHFetchResult
with default behaviour. It seeme so obvious now after discovering that.