How to get a ALAssetRepresentation of a shared photostream ALAsset?

前端 未结 3 1299
渐次进展
渐次进展 2020-12-23 22:49

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

According to the documentation this c

相关标签:
3条回答
  • 2020-12-23 22:51

    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
    
    0 讨论(0)
  • 2020-12-23 23:04

    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 */  }];
    
    0 讨论(0)
  • 2020-12-23 23:13

    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

    0 讨论(0)
提交回复
热议问题