How to load resource in cocoapods resource_bundle

前端 未结 8 2062
说谎
说谎 2020-12-01 10:43

I have struggled a lot to how to load resource in cocoapods resource_bundle.

The following is what i put in the .podspecs file.

s.sourc         


        
8条回答
  •  清歌不尽
    2020-12-01 11:16

    Just for the record: I wanted to open a NIB from a Category stored in a CocoaPods library. Of course [self classForCoder] gave UIKit back (because of the Category), so the above methods didn't work.

    I resolved the issue using some hardcoded paths:

    NSURL *bundleURL = [[[NSBundle mainBundle] resourceURL] URLByAppendingPathComponent:@"Frameworks/MyCocoaPodLibraryName.framework"];
    NSBundle *podBundle = [NSBundle bundleWithURL:bundleURL];
    
    CustomView *customView = [[podBundle loadNibNamed:@"CustomView" owner:self options:nil] firstObject];
    

提交回复
热议问题