如何识别是否没有从iCloud完全下载PHAsset(所以我需要再次使用options.networkAccessAllowed请求) [英] How to identify if a PHAsset is not completely downloaded from iCloud (so I need to request again with options.networkAccessAllowed)

查看:1161
本文介绍了如何识别是否没有从iCloud完全下载PHAsset(所以我需要再次使用options.networkAccessAllowed请求)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文档说:




PHImageResultIsInCloudKey:
A布尔值,指示照片资产数据是否被存储在本地设备上或者必须从iCloud下载。 (NSNumber)
如果是,则不提供图像,因为资产数据必须从iCloud下载。要下载数据,请提交另一个请求,并为networkAccessAllowed选项指定YES。


但是当资产为时,此键始终为YES存储在iCloud照片库中,即使它已经完全下载到设备中(在我的应用程序中下载,也在照片应用程序中打开)。



如果是图像不可用我想给用户下载它的可能性(但不要自动执行,至少在没有Wifi的情况下不这样做。)



所以如何确定是否需要下载图像?



更加好奇:当我的结果块为
requestImageForAsset:targetSize :contentMode:options:resultHandler:为需要下载的图像调用
,在传递较小且降级的版本后,我得到最后一次调用requestedImage == nil。 / p>

在这种情况下,降级为NO,即使我没有图像,图像仍然需要下载fr om iCloud,因为到目前为止,照片应用程序中只有一个小缩略图是本地可用的。



我在不同iOS 8版本(8.1.x,8.2)的iPhone和iPad上进行了测试beta,8.3 beta)行为总是一样的。



一旦我在照片应用中打开图像,结果处理程序的最后一次调用就会有完整尺寸的图像,但是PHImageResultIsInCloudKey仍然是YES。



以下是我请求图片的一些代码:

  PHImageRequestOptions * options = [[PHImageRequestOptions alloc] init]; 
options.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
options.networkAccessAllowed = NO;

[self.imageManager requestImageForAsset:资产的targetSize:大小contentMode:PHImageContentModeAspectFill选项:选择resultHandler:^(*的UIImage requestedImage,NSDictionary的*资讯){
//检查requestedImage和信息键这里
//当加载一个全尺寸的图像,PHImageResultIsInCloudKey的结果仍然是
//当一个全尺寸的图像无法加载的原因,而是在云中,isDegraded是NO和PHImageResultIsInCloudKey是是(一如既往)和requestedImage是nil
}];


解决方案

我可以确认PHImageResultIsInCloudKey不可靠。对于存储在iCloud中的图像,即使原始图像已下载到设备,它也会返回1。这种行为与文档形成对比,我建议在radar.apple.com上报告错误。在我看来,PhotoKit仍然是一个非常不成熟的框架 - 它包含许多问题以及一些奇怪的概念决定。


The docs say:

PHImageResultIsInCloudKey: A Boolean value indicating whether the photo asset data is stored on the local device or must be downloaded from iCloud. (NSNumber) If YES, no image was provided, because the asset data must be downloaded from iCloud. To download the data, submit another request, and specify YES for the networkAccessAllowed option.

But this key is always YES when a asset is stored in the iCloud Photo Library, even when it is already completely downloaded to the device (downloaded it in my app, also opened it in the Photos app).

If an image is not available I want to give the user a possibility to download it (but don't do it automatically, at least not when no Wifi is around).

So how do I find out if the image needs to be downloaded?

Even more curious: When my result block of requestImageForAsset:targetSize:contentMode:options:resultHandler: is called for an image that needs to be downloaded, I get a last call with requestedImage == nil, after a smaller and degraded version was delivered.

In this case degraded is NO, even that I got no image and the image still has to be downloaded from iCloud as only a small thumbnail from the Photos app is locally available so far.

I tested this on iPhones and iPads with different iOS 8 versions (8.1.x, 8.2 beta, 8.3 beta) the behavior is always the same.

Once I opened the image in the Photos app, the last call of the result handler has the full size image, but PHImageResultIsInCloudKey will still be YES.

Here's some code how I request the images:

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
}];

解决方案

I can confirm that PHImageResultIsInCloudKey is not reliable. For images stored in iCloud it returns 1, even though the original image has been downloaded to the device. This behavior is in contrast to the documentation and I would suggest to report a bug at radar.apple.com. PhotoKit in my opinion is still a very immature framework - it contains lots of issues and also some weird conceptional decisions.

这篇关于如何识别是否没有从iCloud完全下载PHAsset(所以我需要再次使用options.networkAccessAllowed请求)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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