如何获得共享照片流ALAsset的ALAssetRepresentation? [英] How to get a ALAssetRepresentation of a shared photostream ALAsset?

查看:236
本文介绍了如何获得共享照片流ALAsset的ALAssetRepresentation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从照片流中访问图片时,有时 [asset defaultRepresentation] 方法返回nil。

When I try to access pictures from a photo stream, sometimes the [asset defaultRepresentation] method returns nil.

根据文档,如果资产尚未在本地可用,则可能发生这种情况。

According to the documentation this can occur if the asset is not (yet) available locally.


此方法从资产中返回nil尚未提供的共享照片流
本地。如果资产将来可用,则会发布ALAssetsLibraryChangedNotification
通知。

This method returns nil for assets from a shared photo stream that are not yet available locally. If the asset becomes available in the future, an ALAssetsLibraryChangedNotification notification is posted.

我在照片中查看照片后.app它也可用于我的应用程序,但显然我想让我的应用程序触发本地下载事件。

Once I view the photo in the Photos.app it becomes available for my app too, but obviously I'd like to have my app trigger the "download locally" event.

我查看了 MyImagePicker 示例代码来自Apple,但它表现出相同的行为(只有缩略图可用)

I looked at the MyImagePicker sample code from Apple, but it exhibits the same behaviour (only a thumbnail is available)

如何制作资产可在本地获取吗?

How can I make the asset available locally?

编辑:自Apple推出 Photos.framework ,并且在iOS9中使用ALAssets已被弃用,这可能永远不会被修复。

Since Apple introduced the Photos.framework in iOS8, and using ALAssets became deprecated in iOS9, this will probably never be fixed.

推荐答案

由于Apple在iOS8中引入了PhotoKit框架,并且所有ALAsset内容在iOS9中都被弃用,因此可以肯定这将永远不会得到修复。

Since PhotoKit framework has been introduced by Apple in iOS8, and all ALAsset stuff became deprecated in iOS9, it's safe to say this will never get fixed.

但是,可以使用新的PhotoKit API正确完成。

This can, however, be done properly with the new PhotoKit API's.

您必须在 PHImageRequestOptions networkAccessAllowed = YES c>当要求提供图像时,如果需要,它将从iCloud下载。

You have to set the networkAccessAllowed = YES on the PHImageRequestOptions when asking for an image, and it will download it from iCloud if needed.

 PHAsset* photoAsset = ...
 CGSize fullImageSize = ...
 PHImageRequestOptions* options = [PHImageRequestOptions new];
 options.networkAccessAllowed = YES;
 [[PHImageManager defaultManager] requestImageForAsset:photoAsset
      targetSize:fullImageSize  contentMode:PHImageContentModeAspectFill
      options:options  resultHandler:^(UIImage *result, NSDictionary *info) {  /* use result image */  }];

这篇关于如何获得共享照片流ALAsset的ALAssetRepresentation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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