2015-01-20 212 views
0

我正在嘗試使用PHFetchOptions的includeAllBurstAssets。 在我的相機膠捲中,有大約5張連拍資產(每張大約有10張照片)。PhotoKit:includeAllBurstAssets in PHFetchOptions not working

枚舉資產的相機膠捲我做了以下內容:

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。

回答

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。

+1

謝謝。我認爲includeAllBurstAssets適用於PHAsset的所有獲取方法。它只適用於fetchAssetsWithBurstIdentifier:asset.burstIdentifier從文檔中不完全清楚, – holtmann 2015-02-13 12:26:04