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];
Since iOS 8.1, the behavior of the fetchAssetsWithMediaType:
and fetchAssetsWithOptions:
methods has changed, and they no longer include photos synchronized to the device from iTunes or photos stored in an iCloud Shared Photo Stream.
Source: Document Revision History and PHAsset Class Reference.
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With