Problem:
I am trying to fetch only the PHAssets that are stored locally and not in iCloud
Issue:
I am looking to filter them out either in the following api calls:
- [PHAssetCollection fetchAssetCollectionsWithType:type subtype:subtype options:fetchOption]
- [PHAsset fetchAssetsInAssetCollection:group options:options];
What I tried and didn’t work:
I tried setting PHAssetSourceTypeUserLibrary in the PHFetchOptions
PHFetchOptions *fetchOption = [PHFetchOptions new];
fetchOption.includeAssetSourceTypes = PHAssetSourceTypeUserLibrary;
PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:type subtype:subtype options:fetchOption];
What works but is slow:
I used networkAccessAllowed = NO
in the PHImageRequestOptions when calling
[[PHImageManager defaultManager] requestImageDataForAsset: self options: imageRequestOptions resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info)
then in the resultHandler I check if there is imageData or PHImageResultIsInCloudKey in the info dictionary.
That works but that’s an expensive operation, especially for a high number of assets in the iCloud (e.g. 10k)
Back to my question, is there a way to filter out the assets using either:
- [PHAssetCollection fetchAssetCollectionsWithType:type subtype:subtype options:fetchOption]
OR - [PHAsset fetchAssetsInAssetCollection:group options:options];
Thanks in advance,
Alex