在iOS 8上,我想获取所有存储在设备上的图片。我的问题是我确实得到了它们,但是其中一些不止一次出现。PHAsset
所有图片的属性(隐藏,mediaSubtypes等)都是相同的,因此例如,我不能排除PHAssetMediaSubtypePhotoHDR
子类型。我发现的唯一方法是不添加具有相同日期的多张图片,但这是在保存具有相同创建日期的多张照片时出现的问题。
有谁知道我为什么要得到这些重复品,以及如何避免这些重复品?
这是我获取图片的方式:
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES],];
PHFetchResult *phAssets = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
您可以尝试使用Moments Collections:
PHFetchResult * moments = [PHAssetCollection fetchMomentsWithOptions:nil];
for (PHAssetCollection * moment in moments) {
PHFetchResult * assetsFetchResults = [PHAsset fetchAssetsInAssetCollection:moment options:nil];
for (PHAsset * asset in assetsFetchResults) {
//Do something with asset, for example add them to array
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句