我正在尝试获取 PhAsset 对象。我想隔离 iCloud Assets 。这是我的代码,
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 Assets ?
最佳答案
这有点 hack,我不得不挖掘资源数组并进行调试以找出我需要的信息。但它有效。虽然这是一个未记录的代码,但我不确定苹果是否会因此而拒绝该应用程序。试一试,看看会发生什么!
// 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
您还可以从 Assets 资源中获取一些其他有用的信息,例如 - 原始文件名、文件大小、文件 url 等。
关于ios - 检查给定的 PHAsset 是 iCloud Assets 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31966571/