我相信我已经用下面的代码解决了它:
NSPredicate *testForPanoramasPredicate = [NSPredicate predicateWithFormat:@"(mediaSubtypes & %i) == %i",PHAssetMediaSubtypePhotoPanorama,PHAssetMediaSubtypePhotoPanorama];
NSArray *testForAllPanoramas = [testForAllPhotos filteredArrayUsingPredicate:testForPanoramasPredicate];
如果您不想做初始图像谓词,也许会更好:
NSPredicate *testForPanoramasPredicate = [NSPredicate predicateWithFormat:
@"(mediaType == %i && (mediaSubtypes & %i) == %i))",
PHAssetMediaTypeImage,PHAssetMediaSubtypePhotoPanorama,PHAssetMediaSubtypePhotoPanorama];
完整的代码可以帮助那些特别想检查专辑是否包含一种特定媒体子类型的人;对于在相册上显示 UI 徽章很有用。
PHFetchResult *assetsInCollection = [PHAsset fetchAssetsInAssetCollection:sub options:fetchOptions];
if (assetsInCollection.count > 0)
{
NSArray *allAssets = [assetsInCollection objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, assetsInCollection.count)]];
NSPredicate *testForPanoramasPredicate = [NSPredicate predicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeImage,PHAssetMediaSubtypePhotoPanorama,PHAssetMediaSubtypePhotoPanorama];
NSPredicate *testForHDRPredicate = [NSPredicate predicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeImage,PHAssetMediaSubtypePhotoHDR,PHAssetMediaSubtypePhotoHDR];
NSPredicate *testForVideosPredicate = [NSPredicate predicateWithFormat:@"mediaType = %i",PHAssetMediaTypeVideo];
NSPredicate *testForSlomoPredicate = [NSPredicate predicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeVideo,PHAssetMediaSubtypeVideoHighFrameRate,PHAssetMediaSubtypeVideoHighFrameRate];
NSPredicate *testForTimelapsePredicate = [NSPredicate predicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeVideo,PHAssetMediaSubtypeVideoTimelapse,PHAssetMediaSubtypeVideoTimelapse];
NSPredicate *testForStreamedPredicate = [NSPredicate predicateWithFormat:@"(mediaType == %i && (mediaSubtypes & %i) == %i))",PHAssetMediaTypeVideo,PHAssetMediaSubtypeVideoStreamed,PHAssetMediaSubtypeVideoStreamed];
NSArray *testForAllPanoramas = [allAssets filteredArrayUsingPredicate:testForPanoramasPredicate];
NSArray *testForAllHDR = [allAssets filteredArrayUsingPredicate:testForHDRPredicate];
NSArray *testForAllVideos = [allAssets filteredArrayUsingPredicate:testForVideosPredicate];
NSArray *testForAllSlomo = [allAssets filteredArrayUsingPredicate:testForSlomoPredicate];
NSArray *testForAllTimelapse = [allAssets filteredArrayUsingPredicate:testForTimelapsePredicate];
NSArray *testForAllStreamed = [allAssets filteredArrayUsingPredicate:testForStreamedPredicate];
NSArray *allPossibilitiesArray = @[testForAllPanoramas,testForAllHDR,testForAllVideos,testForAllSlomo,testForAllTimelapse,testForAllStreamed];
for (NSArray *sub in allPossibilitiesArray)
{
if (sub.count == allAssets.count)
{
PHAsset *firstAsset = sub.firstObject;
[dataSource setObject:[NSNumber numberWithInt:firstAsset.mediaSubtypes] forKey:@"MediaSubtype"];
}
}
}