iOS16系统根据PHAsset判断是否在云上
-(BOOL)getIsInICloudWithAsset:(PHAsset *)asset { if(asset && [asset isKindOfClass:PHAsset.class]) { // asset是一个您想要为其获取信息的PHAsset对象 NSArray *resourceArray = [PHAssetResource assetResourcesForAsset:asset]; if (resourceArray.count >= 1){ ///本地是否可用:NO 代表icould 图片 // If this returns NO, then the asset is in iCloud and not saved locally yet return ![[resourceArray.firstObject valueForKey:@"locallyAvailable"] boolValue]; } NSLog(@"asset 资源信息 resourceArray = %@", resourceArray); if ([[resourceArray.firstObject valueForKey:@"locallyAvailable"] boolValue] == NO){ NSLog(@"图片 不在本地 isLocallayAvailable == NO"); }else{ NSLog(@"图片 在本地 isLocallayAvailable == YES"); } return NO; } return NO; }
注意:iOS16下面的方法获取到的都是NO,并列相信的网上的方法,要看具体系统的。
-(BOOL)getIsInICloudWithAsset:(PHAsset *)asset { __block BOOL isICloudAsset = NO; if(asset && [asset isKindOfClass:PHAsset.class]) { PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.resizeMode = PHImageRequestOptionsResizeModeFast; options.synchronous = true; [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(80, 80) contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *result, NSDictionary *info) { if ([[info objectForKey: PHImageResultIsInCloudKey] boolValue]) { isICloudAsset = YES; }}]; } return isICloudAsset; }