2

嗨,我打电话给 ALAssetsLibrary

-enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:block failureBlock:failure;

然后在枚举块内我想比较返回的组类型并将其添加到相关数组中。我努力了

^( ALAssetsGroup *group, BOOL *stop )
{
    NSLog(@"Group %@", group );
    ALAssetGroupType assetType = (ALAssetGroupType)[group valueForProperty:ALAssetsGroupPropertyType];
    NSLog( @"Asset type %@", assetType );
    switch( assetType )
    {
        case ALAssetsGroupAplbum :
        NSLog( @"Found ALBUM" );
        [albums addObject:group];
        break;
    }
}

初始日志跟踪“组 ALAssetsGroup - 名称:照片库,类型:相册,资产计数:177”

下一个日志是“资产类型 2”

但第三个日志永远不会被调用。

任何想法我做错了什么?

4

1 回答 1

6

valueForProperty: returns an object. In the case of ALAssetsGroupPropertyType it returns an ALAssetGroupType constant wrapped in an NSNumber. (See docs here.)

So by casting to ALAssetGroupType you're using the object's memory address as your switch value. You need to get the underlying integer value of the NSNumber using intValue:

ALAssetGroupType assetType = 
 [[group valueForProperty:ALAssetsGroupPropertyType] intValue];
于 2010-12-11T18:22:46.820 回答