检查给定的 PHAsset 是 iCloud 资产吗?

2024-03-17

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

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 资产?


这有点像黑客,我必须挖掘资源数组并进行调试才能找到我所需的信息。但它有效。虽然这是一个未记录的代码,但我不确定苹果是否会因此而拒绝该应用程序。尝试一下,看看会发生什么!

// asset is a PHAsset object for which you want to get the information    
NSArray *resourceArray = [PHAssetResource assetResourcesForAsset:asset];
BOOL bIsLocallayAvailable = [[resourceArray.firstObject valueForKey:@"locallyAvailable"] boolValue]; // If this returns NO, then the asset is in iCloud and not saved locally yet

您还可以从资产资源中获取一些其他有用的信息,例如原始文件名、文件大小、文件 URL 等。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

检查给定的 PHAsset 是 iCloud 资产吗? 的相关文章

随机推荐