Thy*_*raz 19 ios photokit phasset
文档说:
PHImageResultIsInCloudKey:一个布尔值,指示照片资产数据是存储在本地设备上还是必须从iCloud下载.(NSNumber)如果是,则不提供图像,因为必须从iCloud下载资产数据.要下载数据,请提交另一个请求,并为networkAccessAllowed选项指定YES.
但是当资产存储在iCloud照片库中时,此键始终为YES,即使已将其完全下载到设备中(在我的应用程序中下载,也在照片应用程序中打开).
如果图像不可用,我想让用户可以下载它(但不要自动执行,至少在没有Wifi的情况下不这样做).
那么如何确定图像是否需要下载?
更奇怪的是:当我的结果块
requestImageForAsset:targetSize:contentMode:options:resultHandler:
被调用需要下载的图像时,我会在传递较小且降级的版本之后使用requestedImage == nil进行最后一次调用.
在这种情况下降级为NO,即使我没有图像,仍然必须从iCloud下载图像,因为到目前为止,只有照片应用程序中的一个小缩略图在本地可用.
我在具有不同iOS 8版本(8.1.x,8.2 beta,8.3 beta)的iPhone和iPad上进行了测试,行为总是相同的.
在Photos应用程序中打开图像后,结果处理程序的最后一次调用具有完整大小的图像,但PHImageResultIsInCloudKey仍为YES.
这是我如何请求图像的一些代码:
PHImageRequestOptions *options = [[PHImageRequestOptions alloc]init];
options.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
options.networkAccessAllowed = NO;
[self.imageManager requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *requestedImage, NSDictionary *info) {
// Checking for requestedImage and the info keys here
// When a full sized image was loaded, the result of PHImageResultIsInCloudKey is still YES
// When a full sized image couldn't be loaded cause it's in the cloud, isDegraded is NO and PHImageResultIsInCloudKey is YES (as always) and requestedImage is nil
}];
Run Code Online (Sandbox Code Playgroud)
bca*_*tle 13
如果requestImageDataForAsset:使用networkAccessAllowedset to 调用NO,则返回的imageData内容nil是否尚未从iCloud下载剪辑.否则它将返回实际数据,即使剪辑存储在iCloud中.
PHImageManager *manager = [PHImageManager defaultManager];
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.networkAccessAllowed = NO;
[manager
requestImageDataForAsset:asset
options:options
resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
if ([[info valueForKey:PHImageResultIsInCloudKey] boolValue]) {
// Image is in iCloud
if (imageData) {
// Image is downloaded
} else {
// Image is not downloaded
}
}
}];
Run Code Online (Sandbox Code Playgroud)
我可以确认PHImageResultIsInCloudKey不可靠.对于存储在iCloud中的图像,即使原始图像已下载到设备,它也会返回1.这种行为与文档形成对比,我建议在radar.apple.com上报告错误.在我看来,PhotoKit仍然是一个非常不成熟的框架 - 它包含许多问题以及一些奇怪的概念决策.
| 归档时间: |
|
| 查看次数: |
9286 次 |
| 最近记录: |