使用PHAsset获取图片时避免重复 [英] Avoiding duplicates when getting pictures with PHAsset
问题描述
在iOS 8上,我希望将所有图片存储在设备上。我的问题是我确实得到了它们,但有些不止一次。 PHAsset
属性(隐藏,mediaSubtypes等)对于所有图片都是相同的,所以我不能排除 PHAssetMediaSubtypePhotoHDR
子类型。我找到的唯一方法是不添加具有相同日期的多张图片,但是当使用相同的创建日期保存多张照片时,这是一个问题。
On iOS 8, I want to get all pictures stored on the device. My problem is that I do get them, but some are present more than once. The PHAsset
properties (hidden, mediaSubtypes, etc.) are the same for all pictures, so I can't for example rule out the PHAssetMediaSubtypePhotoHDR
subtypes. The only way I found is not adding multiple pictures with the same date, but this is a problem when multiple photos were saved with the same creation date.
有人知道为什么我得到了这些副本以及我可以做些什么来避免它们?
Does anybody know why I get these duplicates and what I can do to avoid them?
这就是我得到图片的方式:
This is how I get the pictures:
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES],];
PHFetchResult *phAssets = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
推荐答案
您可以尝试使用Moments Collections:
You can try to use 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
}
}
这篇关于使用PHAsset获取图片时避免重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!