How to upload image from Assets.car (compiled version of xcassets) to NSBundle? (without using CocoaPods)

We get these error messages:

Failed to load the image "iconStatus" referenced by the thread bundled with the identifier "com.company.OurResourceBundle".

Basically, we put a bunch of images in the xcassets folder (which works for cases not related to the package). The xcassets and nib files are packaged in a resource package.

When the application starts,

  • The uiimageview in the nib file cannot load images with the above error message.
  • [UIImage imageNamed: @ "OurResourceBundle.bundle / iconStatus"] returns nil

The question is related to " How to load an image from Assets.car (a compiled version of xcassets) into the NSBundle? ", But we do not use CocoaPods.

+4
source share
2 answers

In iOS 7, it is not possible to download images from any .car file, except the one that Xcode compiles into the main package. This was confirmed by the Apple developer at https://devforums.apple.com/message/968859#968859 :

, , , Xcode , + imageNamed: , ( ).

iOS 8 , , , , :

+ (UIImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle
    compatibleWithTraitCollection:(UITraitCollection *)traitCollection
+7

, .car, NSBundle , . . . , . , . , , @2x ~ ipad , .

    NSBundle *myBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"your bundle" ofType:@"bundle"]];
    NSString *filePath = [myBundle pathForResource:@"icon" ofType:@"png"];
    UIImage *image = [UIImage imageWithContentsOfFile:filePath];
-1

Source: https://habr.com/ru/post/1535073/


All Articles