Using the Photos Framework is a little different, you can achieve the same result, but you just need to do it in parts.
1) Get all the photos (Moments in iOS8 or Camera Roll before)
PHFetchResult *allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
Optionally, if you want them to be sorted by creation date, you simply add PHFetchOptions like this:
PHFetchOptions *allPhotosOptions = [PHFetchOptions new]; allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]]; PHFetchResult *allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosOptions];
Now, if you want, you can get assets from the PHFetchResult object:
[allPhotosResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) { NSLog(@"asset %@", asset); }];
2) Get all user albums (with an additional view, for example, to show only albums with at least one photo)
PHFetchOptions *userAlbumsOptions = [PHFetchOptions new]; userAlbumsOptions.predicate = [NSPredicate predicateWithFormat:@"estimatedAssetCount > 0"]; PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:userAlbumsOptions]; [userAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop) { NSLog(@"album title %@", collection.localizedTitle); }];
For each PHAssetCollection returned from PHFetchResult *userAlbums , you can choose PHAssets like this (you can even limit the results to only photo actions):
PHFetchOptions *onlyImagesOptions = [PHFetchOptions new]; onlyImagesOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType = %i", PHAssetMediaTypeImage]; PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:collection options:onlyImagesOptions];
3) Get smart albums
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil]; [smartAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop) { NSLog(@"album title %@", collection.localizedTitle); }];
In smart albums, it should be noted that collection.estimatedAssetCount can return NSNotFound if the AssetCount score cannot be determined. As the name implies, this is rated. If you want to be sure of the number of assets, you must select and get the value count:
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:nil];
number of assets = assetsFetchResult.count
Apple has an example project that does what you want:
https://developer.apple.com/library/content/samplecode/UsingPhotosFramework/ExampleappusingPhotosframework.zip (you must be a registered developer for this)