Search code examples
iphoneobjective-cxcodealassetslibraryalasset

how to prevent ALAssetsLibrary to get video thumbnail images with liabrary images?


I'm using the following code to access all ALAssetsLibrary images but the ALAssetsLibrary is giving me the saved video thumbnail images with the saved images from ALAssetsLibrary. how can i prevent this using the code so that i can get only saved images?

//Method to get all images from devices library
 - (NSMutableArray*)getAllImagesFromLibrary
 {
     //get all images from image library
     void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
     if(result != NULL) {
         //Insert objects into array
         [self.arrOfAllImages addObject:result];
        }
     };

     void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
     if(group != nil) {
         [group enumerateAssetsUsingBlock:assetEnumerator];
        }
     };

     //NSMutableArray allacation
     NSMutableArray *arrOfAllImage = [[NSMutableArray alloc] init];
     static dispatch_once_t pred = 0;
     static ALAssetsLibrary *library = nil;
     dispatch_once(&pred, ^{
         library = [[ALAssetsLibrary alloc] init];
     });

     [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
     usingBlock:assetGroupEnumerator
     failureBlock: ^(NSError *error) {
         NSLog(@"Failure");
     }];

     return arrOfAllImage;

}

Solution

  • Check your result, If it will image the add in array otherwise not

    void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if(result != NULL) {
            if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
            {
                //Insert objects into array
                [self.arrOfAllImages addObject:result];
            }
        }
    };