从iCloud上传PHAsset(即本地设备上不存在的PHAsset) [英] Upload PHAsset from iCloud (i.e. which is not present on the local device )

查看:650
本文介绍了从iCloud上传PHAsset(即本地设备上不存在的PHAsset)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将PHAsset上传到服务器.现在,我的PHAsset可以是照片或视频.对于本地设备上存在的PHAsset,我能够成功完成此操作.但是,如果PHAsset不在本地设备上,而是出现在iCloud上,该怎么办.

I want to upload a PHAsset to the server. Now my PHAsset can be a photo or a video. I am able to do it successfully for the PHAssets present on the local device. But what if the PHAsset is not on the local device and instead present on the iCloud.

我们可以直接从iCloud上载到服务器,还是必须先下载到本地设备,然后再将操作上载到服务器.

此外,如果有人可以告诉我该怎么做,我将不胜感激.

Also, I would be grateful if someone could tell how to do this.

更新:当我们允许网络访问从iCloud下载图像时,出现以下错误.

Update: when we allow the network access to download the image form the iCloud I get this below error.

{

    PHImageErrorKey = "Error Domain=CloudPhotoLibraryErrorDomain Code=1000 \"Error fetching asset with identifier: AUXxudUWWzHheX1dXyRDgXpZN5ty\" UserInfo={NSLocalizedDescription=Error fetching asset with identifier: AUXxudUWWzHheX1dXyRDgXpZN5ty, NSUnderlyingError=0x7fb00a5e9480 {Error Domain=CKErrorDomain Code=6 \"Fetching asset failed\" UserInfo={NSLocalizedDescription=Fetching asset failed, NSUnderlyingError=0x7fb00a511600 {Error Domain=CKInternalErrorDomain Code=2022 \"Fetching asset failed\" UserInfo={NSLocalizedDescription=Fetching asset failed, NSUnderlyingError=0x7fb00a5b6fc0 {Error Domain=com.apple.mmcs Code=16 \"(null)\"}}}}}}";

    PHImageResultDeliveredImageFormatKey = 0;

    PHImageResultIsInCloudKey = 1;

    PHImageResultWantedImageFormatKey = 20002;

}

推荐答案

您应在移动应用程序中下载资产,然后将其上传到服务器.由于沙箱和其他隐私权,我认为无法直接从iCloud上传.安全规则.

You should download the asset inside your mobile app and then upload to your server. I don't think it's possible to upload directly from iCloud because of Sandboxing and other privacy & security rules.

如果您使用PHCachingImageManager& requestImageForAsset,您应该为PHImageRequestOptions指定特殊选项networkAccessAllowed,该选项允许iCloud提取数据,如

If you use PHCachingImageManager & requestImageForAsset, you should specify special option networkAccessAllowed for PHImageRequestOptions which is allow iCloud to fetch data as described in documentation:

如果是,并且请求的资源数据未存储在本地设备上,则Photos从iCloud下载该数据.

If YES, and the requested resource data is not stored on the local device, Photos downloads that data from iCloud.

注意:您应该使用iCloud Documents服务启用iCloud权利并设置默认容器.在此处查看更多详细信息在您的应用程序中启用CloudKit .如我所见,当您使用networkAccessAllowed = true

NOTE: You should enable iCloud entitlement with iCloud Documents service and setup default container. See more details here Enabling CloudKit in Your App. As I can see, it's required when you use networkAccessAllowed = true

例如,您可以像这样为资产经理设置选项:

For example, you can setup options for your asset manager like this:

PHImageRequestOptions *requestOptions = [PHImageRequestOptions new];
requestOptions.synchronous = NO;
requestOptions.resizeMode = PHImageRequestOptionsResizeModeFast;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
requestOptions.networkAccessAllowed = YES;

然后请求数据

[self.cachingImageManager requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:requestOptions resultHandler:^(UIImage * _Nullable resultImage, NSDictionary * _Nullable info) {
...
}];

在这种情况下,您将了解iCloud如何在调用resultHandler之前在文档选择器中获取数据,在这里您可以处理请求的资产.

In this case, you'll see how iCloud fetch data inside document picker before make a call to resultHandler where you can handle the requested asset.

这篇关于从iCloud上传PHAsset(即本地设备上不存在的PHAsset)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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