Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a ALAssetRepresentation of a shared photostream ALAsset?

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.

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.

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.

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?

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

like image 253
Pieter Avatar asked Aug 06 '13 12:08

Pieter


2 Answers

I fall into same issue. I couldn't find a way to actually get the images. All you can do is not display images that have "defaultRepresentation" nil or drop support for Shared photos at all by calling [ALAssetsLibrary disableSharedPhotoStreamsSupport];

Hope that helps

like image 182
Inshiqaq Avatar answered Nov 16 '22 09:11

Inshiqaq


I found the answer! It is not documented and therefor use the following answer with caution. (With caution I mean, Apple doesn't allow to use private API calls).

On the asset there is a method named - (void)requestDefaultRepresentation; you can use this method to trigger the Asset Library to download the shared photo. As stated in the document the ALAssetsLibraryChangedNotification will be fired to let you know the image became available.

No idea, why Apple didn't document it. Good luck have fun =)

You can avoid a warning with the following header:

ALAsset+RequestDefaultRepresentation.h

#import <AssetsLibrary/AssetsLibrary.h>

@interface ALAsset (RequestDefaultRepresentation)
- (void)requestDefaultRepresentation;
@end
like image 2
Mark Avatar answered Nov 16 '22 10:11

Mark