Check given PHAsset is iCloud asset?

后端 未结 6 1167
再見小時候
再見小時候 2021-02-02 14:16

I\'m trying to get PhAsset object. I want to segregate iCloud assets. Here is my code,

PHFetchResult *cloudAlbums = [PHAssetCollection fetchAssetCollectionsWithT         


        
6条回答
  •  攒了一身酷
    2021-02-02 14:59

    There are actually 2 kinds of situations: 1. The photo is captured by this device, and is uploaded to iCloud. Then, you can use the progressHandler to check whether it needs iCloud download.

    __block BOOL isPhotoInICloud = NO;
    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
    options.networkAccessAllowed = YES;
    options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
    options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info){
    
            isPhotoInICloud = YES;
    
    });
    
    [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFit options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
    
            if (isPhotoInICloud) {
                // Photo is in iCloud.
            }
    });
    
    1. The photo is in iCloud but uploaded from other device. And you did not save it to your local photo library. So the progressHandler block will never ever be invoked. I don't know why but it's true, and I think it's kind of a bug of PhotoKit framework. For this situation, if you use the PHImageResultIsInCloudKey, that is also difficult. Because you can know the PHImageResultIsInCloudKey value just in the requestImageForAsset's resultHandler block. But that's the time after the photo request is initiated.

    So, at least, in my opinion, there is no way to check whether photo is stored in iCloud. Maybe there is other better way, please let me know. Thanks very much!

提交回复
热议问题