在ios中加载照片库

时间:2014-05-01 18:24:06

标签: ios photo alassetslibrary

我有这种静态方法可以返回我相册的所有照片。问题是当我运行这个应用程序时,该函数运行两次:一次返回没有图像,并且一旦将图像放在所有图像数组中但没有返回。我很困惑,我做错了什么?

 + (NSMutableArray *)photosAssest
   {
     NSMutableArray *allImages = [NSMutableArray new];

    ALAssetsLibrary *library = AssatLibaryHelper.defaultAssetsLibrary;



    [library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop)
    {

       NSInteger numberOfAssets = [group numberOfAssets];
       if (numberOfAssets > 0)
       {

         for (int i = 0; i <= numberOfAssets-1; i++)
         {
              [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:i] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
              {
                  if (result != nil)
                  {
                      UIImage *thumbnail = [UIImage imageWithCGImage:[result thumbnail]];
                      [allImages addObject:thumbnail];
                  }
              }];
         }

     }

 }
                     failureBlock:^(NSError *error)
 {

 }];


return allImages;

}

0 个答案:

没有答案