Question

I am looking for a way to find the ALAsset of a given ALAssetsGroup that corresponds to its posterImage.

The posterImage property of the group only returns a CGImage, and I'd like to get the ALAsset that the image matches. Is this possible enumerateAssetsWithOptions over the group, I can't find any properties that would match or indicate which assets is the poster.

Was it helpful?

Solution

As far as I know, there is no such way. But posterImage is usually the most recent asset in the ALAssetsGroup (Not true for ALAssetsGroupAlbum, always true for ALAssetsGroupSavedPhotos). And the documentation says about the order of the assets in a group:

"An ALAssetsGroup object represents an ordered set of the assets managed by the Photos application. The order of the elements is the same as the user sees in the Photos application. An asset can belong to multiple assets groups".

With this assumption, you can achieve the posterImage as an ALAsset something like this:

ALAssetsGroup * group;
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop)
{
    if (alAsset) // first non-nil element will be the recent asset
    {
        * innerStop = YES;

        // do something with the alAsset
    }
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top