Search code examples
iosobjective-cswiftphotokit

PHFetchOptions for PHAsset in same sort order as Photos.app


I'm using the new PHFetchOptions' sortDescriptors for getting PHAssets from the camera roll. There seem to only be two keys to sort on: creationDate and modificationDate, neither of which are the same as what you see in the Photos.app.

Am I missing something? How can we get this to work?


Solution

  • I have used the following code to get the list of smart albums which includes the "Camera Roll":

    // get the smart albums
    PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
    for (NSInteger i = 0; i < smartAlbums.count; i++) {
        PHAssetCollection *assetCollection = smartAlbums[i];
        // Then use the following to get the photo images:
        PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:nil];
        }
    

    The default sort order is the existing order of assets in collections including the "Camera Roll". Passing "nil" for options gets the default. You can reorder the images in the camera roll and this code will reflect the changes.