ios – 使用PHAsset获取图片时避免重复

在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
    }
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...