Unable to use iOS framework which is internally using .xib file

前端 未结 8 2267
你的背包
你的背包 2020-12-16 19:14

I am trying to make a universal framework, for iOS by following steps specified in this URL: Universal-framework-iOS

I have a viewController class within, that frame

8条回答
  •  心在旅途
    2020-12-16 19:30

    Unfortunately because iOS does not have an exposed concept of dynamic fragment loading some of NSBundle's most useful functionality is a little hard to get to. What you want to do is register the framework bundle with NSBundle, and from then on you can find the bundle by it's identifier - and the system should be able to correctly find nibs, etc. within that bundle. Remember, a framework is just a kind of bundle.

    To make NSBundle "see" your bundle and it's meta information (from it's Info.plist), you have to get it to attempt to load the bundle. It will log an error because there will be no CFPlugin class assigned as a principal class, but it will work.

    So for example:

    NSArray *bundz = [[NSBundle bundleForClass:[self class]] URLsForResourcesWithExtension:@"framework" subdirectory:nil];
    for (NSURL *bundleURL in bundz){
        // This should force it to attempt to load. Don't worry if it says it can't find a class.
        NSBundle *child = [NSBundle bundleWithURL:bundleURL];
        [child load];
    }
    

    Once that is done, you can find your framework bundle using bundleWithIdentifier:, where the identifier is the CFBundleIdentifier in your framework's Info.plist. If you need to use UINib directly to load your view controller nib directly at that point, it should be easy to locate the bundle using bundleWithIdentifier: and give that value to nibWithNibName:bundle: .

提交回复
热议问题