Access Resources in pod

后端 未结 2 1757
遇见更好的自我
遇见更好的自我 2021-02-02 16:21

I would like to include image assets in a cocoapod library, but I\'m having trouble accessing them. I\'ve read these resources for help:

Cocoapods Resources

Coco

2条回答
  •  死守一世寂寞
    2021-02-02 16:51

    This tripped me up too. Maybe I'm misunderstanding +bundleWithIdentifier:, but I don't think you can use it to get to a resource bundle inside of your iOS app bundle. See the "Getting Bundles by Identifier" section of the bundle docs for more details.

    What does work is +bundleWithPath:, e.g.:

    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"MyResourceBundle" ofType:@"bundle"];
    NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
    

    I wrapped that inside of a dispatch_once block and call it any time I need to access this bundle.

    I'm using the s.resource_bundles syntax in my podspec as well and this works fine with it.

提交回复
热议问题