With the iOS Photos Framework how do I list all PHAssetCollections available?

Andrew Paul Simmons picture Andrew Paul Simmons · Mar 10, 2015 · Viewed 11.3k times · Source

With the iOS Photos Framework how do I list all PHAssetCollections available? I'd like to find the "Photo Roll" collection so that I can retrieve all photos from that collection, specifically. How do I do that with the iOS 8+ using the new PhotosFramework?

Answer

Mike Clark picture Mike Clark · Mar 10, 2015

Use below given code snippet to get the all Smart Albums and All smart photos

// Get all Smart Albums 
  PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];

 [smartAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop) {
    NSLog(@"album title %@", collection.localizedTitle);
}];


//    Get all photos
PHFetchResult *allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];


//   Get assets from the PHFetchResult object
[allPhotosResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
   NSLog(@"asset %@", asset);
   CGSize size=CGSizeMake(90, 90);
   PHImageManager *imageManager;
   [imageManager requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeAspectFit options:nil resultHandler:^(UIImage *result, NSDictionary *info) {
           yourImageView.image=result;

       }];
}];

for reference:https://developer.apple.com/library/prerelease/ios/samplecode/UsingPhotosFramework/Introduction/Intro.html