Frage

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;

}
War es hilfreich?

Lösung 2

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];
        }
    }
};

Andere Tipps

Set a filter before you enumerate:

[group setAssetsFilter: [ALAssetsFilter allPhotos]];

You can mention many types of Asset through ALAssetsGroupType

They are

   ALAssetsGroupLibrary        
   ALAssetsGroupAlbum          
   ALAssetsGroupEvent          
   ALAssetsGroupFaces          
   ALAssetsGroupSavedPhotos    
   ALAssetsGroupPhotoStream    
   ALAssetsGroupAll  

1

ALAssetsGroupLibrary

The Library group that includes all assets that are synced from iTunes.

Available in iOS 4.0 and later.

Declared in ALAssetsLibrary.h.

2

ALAssetsGroupAlbum

All the albums created on the device or synced from iTunes, not including Photo Stream or Shared Streams

Available in iOS 4.0 and later.

Declared in ALAssetsLibrary.h.

3

ALAssetsGroupEvent

All events, including those created during Camera Connection Kit import.

Available in iOS 4.0 and later.

Declared in ALAssetsLibrary.h.

4

ALAssetsGroupFaces

All the faces albums synced from iTunes.

Available in iOS 4.0 and later.

Declared in ALAssetsLibrary.h.

5

ALAssetsGroupSavedPhotos

All the photos in the Camera Roll.

Available in iOS 4.0 and later.

Declared in ALAssetsLibrary.h.

6

**ALAssetsGroupPhotoStream**

The PhotoStream album.

In iOS 6.0 and later, this also includes Shared Streams.

Available in iOS 5.0 and later.

Declared in `ALAssetsLibrary.h`.

7

ALAssetsGroupAll

The same as ORing together all the group types except for ALAssetsGroupLibrary.

Available in iOS 4.0 and later.

Declared in ALAssetsLibrary.h.

You can see more details developer.apple

Example:

 [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
     usingBlock:assetGroupEnumerator
     failureBlock: ^(NSError *error) {
         NSLog(@"Failure");
     }];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top