0

I am developing an iPad application in which I have saved images to custom album using This.

Now I want to get all the images from that custom folder and I need to show all those in a animated UIImageView.

I know how to set animation but I want to know how to get all the images from particular custom folder.

Ravi Raman
  • 1,070
  • 9
  • 16
ganesh
  • 131
  • 2
  • 11

1 Answers1

1

See this code I used to load the images from the custom album. I have used the same sample code to store my images in custom album.

NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    self.assetGroups = tempArray;

    library = [[ALAssetsLibrary alloc] init];      

    // Load Albums into assetGroups

        // Group enumerator Block
        void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) 
        {
            if (group == nil) 
            {
                return;
            }
            if([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:kAlbumName])
            {
                [self.assetGroups addObject:group];
                [self reloadTableView];
                return;
            }
        };

        // Group Enumerator Failure Block
        void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) {

            CustomAlertView * alert = [[CustomAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"Album Error: %@ - %@", [error localizedDescription], [error localizedRecoverySuggestion]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];

            NSLog(@"A problem occured %@", [error description]);                                     
        };  

        // Enumerate Albums
        [library enumerateGroupsWithTypes:ALAssetsGroupAll
                               usingBlock:assetGroupEnumerator 
                             failureBlock:assetGroupEnumberatorFailure];

Here the kAlbumName is one string ivar which contains the custom album name.

EDIT:1

Above code just gives you the whole album selected with all it photos now to get those photos from album use the following code

[self.assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) 
     {         
         if(result == nil) 
             return;
     CGRect viewFrames = kThumbSize;//CGRectMake(0, 0, 75, 75);
         UIImageView *assetImageView = [[UIImageView alloc] initWithFrame:viewFrames];
        [assetImageView setContentMode:UIViewContentModeScaleToFill];
        [assetImageView setImage:[UIImage imageWithCGImage:(__bridge CGImageRef)([result originalAsset])]];
     }];

NOTE: Instead of kThumbSize define your CGRectMake() as commented.

Enjoy coding :) Happy Day :)

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
  • Use of below link I got array of images its working fine in simulator but not in device Why ? http://stackoverflow.com/questions/10040731/how-do-i-get-access-to-the-album-i-saved-photos-like-in-camera-app – ganesh Oct 15 '12 at 13:53
  • What happend when you run the app on device? Does it give any error or just not shows any image? – The iOSDev Oct 16 '12 at 05:13
  • It not show any images,it just executes failure blocks and says alert message No album found – ganesh Oct 16 '12 at 05:42
  • That means there is no album named in the code ie if you have put `MyAlbum` as album name that named album is not there on your device Please check that out which name you have put in code and is there that named album on your device using the photos app on device – The iOSDev Oct 16 '12 at 05:44
  • There must be no album created on your device so code is not able to find out the album named in your code double check that as the alert message suggest in your simulator you have created album by your app or manually. – The iOSDev Oct 16 '12 at 05:47
  • If there is no album you want to access in your album list just create it by app in code or manually for testing and run the code (on your device) This will solve your problem :) – The iOSDev Oct 16 '12 at 05:48
  • If still there is error just put your code snippets for saving and retrieving images and let me check that code. If you want to share it with me so I can find out the problem :) – The iOSDev Oct 16 '12 at 05:51
  • Or you can ask for mail-id to send me code snippets so that I can find out the problem in your code if you want :) – The iOSDev Oct 16 '12 at 05:52
  • At present from the alert I can only say that there would be only one problem and it is with photo album is not present on your device. – The iOSDev Oct 16 '12 at 05:54
  • I have album in my device in same name which i given in code, Here is my code for Check, http://stackoverflow.com/questions/12907577/ipad-get-images-from-custom-album-device-issue – ganesh Oct 16 '12 at 05:55
  • After properly checking just tell me if there is album on device which you are trying to find is already there on device and is still it is not been found out by code then there will must be some mistake in code as I can able to save and retrive all my images from my custom album with this code – The iOSDev Oct 16 '12 at 05:56
  • did you seen my code, where i did mistake i have created the custom album and named it to ganesh. But, it works perfect in simulator not in device where is the mistake in my code – ganesh Oct 16 '12 at 06:00