Ipad Get Images from custom album Device Issue

Deadly 提交于 2019-12-13 18:31:33

问题


Am having a Custom folder in my ipad device. Am using this code to get image from Custom album:

self.assetGroups = [[NSMutableArray alloc] init];
// Group enumerator Block
dispatch_async(dispatch_get_main_queue(), ^
{
   void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
   {
       if (group == nil) {
           return;
       }
       if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:@"Ganesh"]) {
           [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:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
       [alert show];
       [alert release];
   };

    // Enumerate Albums
    self.library = [[ALAssetsLibrary alloc] init];
    [library enumerateGroupsWithTypes:ALAssetsGroupAll
    usingBlock:assetGroupEnumerator
    failureBlock:assetGroupEnumberatorFailure];
});

To retrieve all the images from my custom folder I am using this:

(void)loadImages {
    ALAssetsGroup *assetGroup = [self.assetGroups objectAtIndex:0];

    NSLog(@"asserts group %@",self.assetGroups);
    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]];
     NSLog(@"image name%@",img);
     [arrayOfImage addObject:img];
     NSLog(@"arrayOfImage %@",arrayOfImage);
     // [imageToAnimate setImage:img];
     }];
}

its working fine when i am running with simulator but not in device: it executes Failure block and Says No Album Available.


回答1:


Its works fine. I have switched Off my location service due to this am not able to access my media now it works fine.



来源:https://stackoverflow.com/questions/12907577/ipad-get-images-from-custom-album-device-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!