检查给定的PHAsset是iCloud资产吗? [英] Check given PHAsset is iCloud asset?

查看:750
本文介绍了检查给定的PHAsset是iCloud资产吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取PhAsset对象。我想隔离iCloud资产。这是我的代码,

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

PHFetchResult *cloudAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];

[cloudAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop){
    if(collection != nil){

        PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:collection options:fetchOptions];
        [result enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop)
         {
            // check asset is iCloud asset 

         }];
    }

}];

请告诉我如何找到PHAsset是iCloud资产?

Please tell me how to find the PHAsset is iCloud asset?

推荐答案

实际上有两种情况:
1.照片由此设备捕获,并上传到iCloud。然后,您可以使用progressHandler检查是否需要iCloud下载。

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. 照片在iCloud中,但是从其他网站上传设备。而且您没有将其保存到您当地的照片库。因此,永远不会调用progressHandler块。我不知道为什么,但这是真的,我认为这是PhotoKit框架的一个错误。
    对于这种情况,如果你使用PHImageResultIsInCloudKey,这也很困难。因为您可以在requestImageForAsset的resultHandler块中知道PHImageResultIsInCloudKey值。但这是照片请求启动后的时间。

所以,至少在我看来,没有办法检查是否照片存储在iCloud中。
也许还有其他更好的方法,请告诉我。
非常感谢!

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!

这篇关于检查给定的PHAsset是iCloud资产吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆