2

我已使用代码将照片保存到我的应用程序中的自定义相册

[library saveImage:self.capturedImg toAlbum:@"FunCam" withCompletionBlock:^(NSError *error) {
    if (error!=nil) {
        NSLog(@"Big error: %@", [error description]);
    }
}];

现在,当用户单击某个按钮并在视图中显示它们时,我想检索保存到该相册的所有照片,如相机应用程序(iphone 上的默认应用程序)显示

请帮助我,我该怎么做?

提前致谢

4

1 回答 1

4

试试这些方法...

-(void)loadNewLibraryImages
{
    self.assetGroups = [[NSMutableArray alloc] init];
    // Group enumerator Block
    dispatch_async(dispatch_get_main_queue(), ^
                   {    
                       void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) 
                       {
                           if (group == nil) 
                           {
                               return;
                           }
                           if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:@"YOUR ALBUM NAME"]) {
                               [self.assetGroups addObject:group];                             
                               [self loadImages];
                               return;
                           }                           

                           if (stop) {
                               return;
                           }

                       };

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

                           UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:[NSString stringWithFormat:@"No Albums Available"] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                           [alert show];
                           [alert release];
                       };   

                       // Enumerate Albums
                       ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];        
                       [library enumerateGroupsWithTypes:ALAssetsGroupAll
                                              usingBlock:assetGroupEnumerator 
                                            failureBlock:assetGroupEnumberatorFailure];


                   });


}

-(void)loadImages
{   
    //for (ALAssetsGroup *assetGroup in self.assetGroups) {
//  for (int i = 0; i<[self.assetGroups count]; i++) {

        ALAssetsGroup *assetGroup = [self.assetGroups objectAtIndex:0];
        NSLog(@"ALBUM NAME:;%@",[assetGroup valueForProperty:ALAssetsGroupPropertyName]);

        [assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) 
         {         
         if(result == nil) 
         {
         return;
         }
            UIImage *img = [UIImage imageWithCGImage:[[result defaultRepresentation] fullScreenImage] scale:1.0 orientation:(UIImageOrientation)[[result valueForProperty:@"ALAssetPropertyOrientation"] intValue]];         

         }];  

//  }
}

希望他们会有所帮助....

于 2012-04-06T08:59:10.700 回答