如何获得共享照片streamALAsset的ALAssetRepresentation?

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

根据文件,这可能发生,如果资产尚未(本地)可用。

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

一旦我在Photos.app中查看照片,它也可用于我的应用程序,但显然我希望让我的应用程序触发“本地下载”事件。

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

我如何使资产在当地可用?

编辑:由于苹果在iOS8中引入了Photos.framework ,并且使用ALAssets在iOS9中已被弃用,所以这可能永远不会被修复。

我陷入了同样的问题。 我无法find实际获取图像的方法。 你只能通过调用[ALAssetsLibrary disableSharedPhotoStreamsSupport];显示“defaultRepresentation”为零的图像或者不支持共享照片[ALAssetsLibrary disableSharedPhotoStreamsSupport];

希望有所帮助

我find了答案! 它没有logging,因此谨慎使用以下答案。 (谨慎地说,苹果公司不允许使用私人API调用)。

在资产上有一个名为- (void)requestDefaultRepresentation; 您可以使用此方法触发资源库以下载共享照片。 正如文档中所述, ALAssetsLibraryChangedNotification将被激发,让您知道图像变得可用。

不知道,为什么苹果没有logging它。 祝你好运开心=)

您可以通过以下标题避免警告:

ALAsset + RequestDefaultRepresentation.h

 #import <AssetsLibrary/AssetsLibrary.h> @interface ALAsset (RequestDefaultRepresentation) - (void)requestDefaultRepresentation; @end 

由于PhotoKit框架已经在iOS8中由Apple引入,并且所有ALAsset的东西都在iOS9中被弃用,所以可以肯定地说这永远不会被修复。

但是,这可以用新的PhotoKit API来完成。

请求图像时,必须在PHImageRequestOptions上设置PHImageRequestOptions networkAccessAllowed = YES ,如果需要,将从iCloud下载。

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