2011-09-27 25 views

回答

5

查看ALAssetsLibrary here的文档。要访问需要枚举照片库中所有组(相册)的所有照片和视频,然后枚举每个组中的所有照片和图像。您无法使用API​​删除资产。 iOS 5增加了额外的功能 - 它仍然处于NDA之下,无法在这里讨论 - 查看Beta版文档以及适用于iOS5的Apple开发人员论坛。

您的代码将需要做这样的事情:

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init]; 


[al enumerateGroupsWithTypes:ALAssetsGroupAll 

    usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
    { 
     [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) 
     { 
      if (asset) 
      {     
       .. do something with the asset 
      } 
     } 
     ]; 
    } 

    failureBlock:^(NSError *error) 
    { 
     // User did not allow access to library 
     .. handle error 
    } 
]; 
+0

感谢。我遇到了资产组的问题,你帮了我。 – DmitryR

9

上面的代码已经错过了一些支撑,因此解决以下

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init]; 
assets = [[NSMutableArray alloc] init]; 
[al enumerateGroupsWithTypes:ALAssetsGroupAll 

        usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
{ 
    [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) 
     { 
      if (asset) 
      { 
       NSLog(@"%@",asset); 

       NSLog(@".. do something with the asset");  
      } 
     } 
     ]; 
} 

         failureBlock:^(NSError *error) 
     { 
      // User did not allow access to library 
     // .. handle error 
     } 
     ] ;