PhotoKit:PHFetchOptions中的includeAllBurstAssets不起作用

时间:2015-01-20 21:13:38

标签: photokit phasset phphotolibrary phfetchoptions

我正在尝试使用PHFetchOptions的includeAllBurstAssets。 在我的相机胶卷中,大约有5个爆发资产(每张约有10张照片)。

要枚举相机胶卷中的资产,我正在执行以下操作:

PHFetchOptions *fetchOptions = [PHFetchOptions new];

fetchOptions.includeAllBurstAssets = YES;

PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:fetchOptions];
PHFetchResult *assetFetch = [PHAsset fetchAssetsInAssetCollection:fetchResult[0] options:fetchOptions];

NSLog(@"Found assets %lu",(unsigned long)assetFetch.count);

无论如何,如果我将includeAllBurstAssets属性设置为NO或YES,我将获得完全相同的资产计数。 如果includeAllBurstAssets设置为YES,我预计数字会更高。 这是一个错误还是我以错误的方式解释了includeAllBurstAssets。

1 个答案:

答案 0 :(得分:2)

有一种特殊的方法可以查询突发序列的所有图像。

[PHAsset fetchAssetsWithBurstIdentifier:options:]

在您的情况下,您需要遍历您的assetFetch对象并检查PHAsset是否代表突发。

PHAsset定义了属性BOOL representsBurst

如果返回YES,则获取该突发序列的所有资产。

以下是可能有助于理解的代码段:

if (asset.representsBurst) {
    PHFetchOptions *fetchOptions = [PHFetchOptions new];
    fetchOptions.includeAllBurstAssets = YES;
    PHFetchResult *burstSequence = [PHAsset fetchAssetsWithBurstIdentifier:asset.burstIdentifier options:fetchOptions];
    PHAsset *preferredAsset = nil;
    for (PHAsset *asset_ in burstSequence) {
        if (PHAssetBurstSelectionTypeUserPick == asset.burstSelectionTypes || PHAssetBurstSelectionTypeAutoPick == asset.burstSelectionTypes) {
            asset = preferredAsset = asset_;
        }
    }
    if (!preferredAsset) {
        asset = burstSequence.firstObject;
    }
} 

如您所见,burstSelectionTypes并不总是设置为resp。对于突发序列的所有资产,有时是PHAssetBurstSelectionTypeNone。

相关问题