Question

I'm implemented the ALAsset library for getting the device or local gallery images to my application.Its working in iOS 6 device.But if i'm trying to run the same app in iOS 7 the gallery images are not display. Please anybody suggest me how to resolve this. Sorry for the poor English.

Was it helpful?

Solution

Use this code it works perfectly in all iOS versions


//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) {
             if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
             {
                 //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;

}


Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top