Upload PHAsset from iCloud (i.e. which is not present on the local device )

此生再无相见时 提交于 2019-12-23 04:55:12

问题


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.

Can we upload directly from the iCloud to the server or do we have to first download to the local device and then to upload operation to the server.

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


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;

}

回答1:


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.

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

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

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;

and then request data

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

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.



来源:https://stackoverflow.com/questions/40749624/upload-phasset-from-icloud-i-e-which-is-not-present-on-the-local-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!