Search code examples
iossortingphotokit

Sorting Shared Albums with the Apple IOS Photokit


Before I do a lot of fruitless experimenting, does anyone know if you can sort shared albums using the Apple Photokit. I know the native photos app is not able to.


Solution

  • As far i understand from your question, you want to sort based on the timestamp at which asset was added. Try this:

    _assets = [[NSArray alloc] init];
    
    PHFetchOptions *options = [[PHFetchOptions alloc] init];
    //Sort according to date
    options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
    //If you want just images
    options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeImage];
    //Each album is an assetCollection
    PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:self.assetsCollection options:options];
    _assets = fetchResult;