2013-03-22 156 views
7

我列舉使用ALAssetsLibraryALAssetsLibrary得到相機膠捲

這裏所有的資產組爲代碼:

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

void (^enumerate)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) 
{ 
    if (group == nil) 
    { 
     // enumerated all albums.. 
    } 

    // I hot to check if group is Camera Roll ? 

}; 

[library enumerateGroupsWithTypes:ALAssetsGroupAll 
         usingBlock:enumerate 
        failureBlock:nil]; 

如何檢查是否當前的一些枚舉是CameraRoll

編輯:正如我測試它始終是最後一個,使用這個枚舉。但我不確定這是否是規則,是否有任何我錯過的參考?

回答

14

要想從相機膠捲的照片使用ALAssetsGroupSavedPhotos同時枚舉資產庫:

[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos 
         usingBlock:enumerate 
        failureBlock:nil]; 

來檢測一下組您目前得到:

if ([[group valueForProperty:@"ALAssetsGroupPropertyType"] intValue] == ALAssetsGroupSavedPhotos) 
{ 
    NSLog(@"Camera roll"); 
} 
+0

我看到了有關這個解決方案,但我需要要知道我列舉的哪些組是相機膠捲,請看代碼 – 2013-03-22 12:23:49

+0

謝謝,這是我想要的!:) – 2013-03-22 12:40:18

3
imageArray = [[NSArray alloc] init]; 
    NSMutableArray*mutableArray =[[NSMutableArray alloc]init]; 

    NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init]; 

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

void (^enumerate)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) 
{ 
    if ([[group valueForProperty:@"ALAssetsGroupPropertyType"] intValue] == ALAssetsGroupSavedPhotos) 
    { 
     NSLog(@"Camera roll"); 
     [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 
      ALAssetRepresentation *rep = [result defaultRepresentation]; 
      NSLog(@"Asset Name ----> %@",rep.filename); 


     }]; 
    } 
    // I hot to check if group is Camera Roll ? 

}; 

[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos 
         usingBlock:enumerate 
        failureBlock:nil]; 
相關問題