0

我正在尝试使用 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。

4

1 回答 1

1

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

[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 并不总是分别设置。对于突发序列的所有资产,有时是 PHAssetBurstSelectionTypeNone。

于 2015-02-02T01:28:07.120 回答