iosobjective-calassetphotostream

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.


Solution

  • 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.

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

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