Lottie-ios: Cannot access pathForResource from Assets catalog

Created on 14 Mar 2018  路  3Comments  路  Source: airbnb/lottie-ios

Check these before submitting:

  • [+] Updated to the latest version of Lottie (2.5.0)
  • [+] The issue doesn't involve an Unsupported Feature
  • [+] This issue isn't related to another open issue

This issue is a:

  • [+] Non-Crashing Bug (Visual or otherwise)
  • [] Crashing Bug
  • [] Feature Request
  • [+] Regression (Something that once worked, but doesn't work anymore)

What Platform are you on?

  • [] MacOS
  • [+] iOS

Code Example

2.1.5 code

NSArray *components = [asset.imageName componentsSeparatedByString:@"."];
image = [UIImage imageNamed:components.firstObject inBundle:asset.assetBundle compatibleWithTraitCollection:nil];

2.5.0 Code

NSString *imagePath = [asset.assetBundle pathForResource:asset.imageName ofType:nil];
image = [UIImage imageWithContentsOfFile:imagePath];

When using image inside assets catalog, pathForResource return nil in LOTLayerContainer line 164.
Can anyone help to resolve issue?

Most helpful comment

+1 to this. It looks like LOTLayerContainer -setImageForAsset: only tries to find images in a file directory, in the image cache, or in the assetBundle using pathForResource, the latter of which does not work with Asset catalogs. It'd be great (and not too much of a fix, I believe) if they added an extra case of just trying to use UIImage +imageNamed:inBundle:compatibleWithTraitCollection: to find images in asset catalogs.

All 3 comments

+1 to this. It looks like LOTLayerContainer -setImageForAsset: only tries to find images in a file directory, in the image cache, or in the assetBundle using pathForResource, the latter of which does not work with Asset catalogs. It'd be great (and not too much of a fix, I believe) if they added an extra case of just trying to use UIImage +imageNamed:inBundle:compatibleWithTraitCollection: to find images in asset catalogs.

Lottie has been completely rewritten in Swift as of 3.0 (https://github.com/airbnb/lottie-ios/pull/777)

I am closing all issues prior to this release to reduce the noise. If you continue to run into this issues or any issue with Lottie 3.0 please open a new ticket

For continued support of Lottie Objective-c please point to this branch: https://github.com/airbnb/lottie-ios/tree/lottie/objectiveC

Was this page helpful?
0 / 5 - 0 ratings

Related issues

loganblevins picture loganblevins  路  3Comments

ricardohochman picture ricardohochman  路  4Comments

petoye picture petoye  路  3Comments

muraterd picture muraterd  路  5Comments

awschuerholz picture awschuerholz  路  3Comments