ios – 如何确定PHAsset是不是完全从iCloud下载(所以我需要再次请求options.networkAccessAllowed)

文件说:

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.

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

如果图像不可用,我想给用户一个下载的可能性(但是不要自动执行,至少在没有Wifi时).

那么如何查看图片是否需要下载呢?

更好奇:当我的结果块
requestImageForAsset:的targetSize:contentMode:选项:resultHandler:
被要求需要下载的图像,在得到一个较小和降级的版本后,我得到了requestImage == nil的最后一次调用.

在这种情况下,即使没有图像,即使我没有图像,图像仍然必须从iCloud下载,因为只有当前可用的照片应用程序的一个小缩略图.

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

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

解决方法

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

以上是来客网为你收集整理的ios – 如何确定PHAsset是不是完全从iCloud下载(所以我需要再次请求options.networkAccessAllowed)全部内容,希望文章能够帮你解决ios – 如何确定PHAsset是不是完全从iCloud下载(所以我需要再次请求options.networkAccessAllowed)所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。