为什么iOS模拟器会加载我的iOS捆绑包但设备却没有?

时间:2017-09-07 11:10:54

标签: ios objective-c iphone xcode bundle

我创建了一个包含故事板和简单按钮的包来执行警报。 然后我将这个.bundle文件拖放到我要使用的其他Xcode项目中。 构建项目时,捆绑包将显示在应用程序的根文件夹中。 我使用以下代码加载包:

NSString* fullPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"OCRSubBundle.bundle"];

NSBundle *bundle = [NSBundle bundleWithPath:fullPath];

NSString *bundleIdentifier = [bundle bundleIdentifier];

NSLog(@"Bundle identifier for subbundle: %@", bundleIdentifier);

NSLog(@"Storyboard with relative path bundle path: %@", bundle);

[bundle load];

NSLog(@"Storyboard with relative path bundle path: %@", bundle);

然后我像这样加载包内的故事板:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"defaultStoryboard" bundle:bundle];

UIViewController *vc = [sb instantiateInitialViewController];

[self presentViewController:vc animated:YES completion:NULL];

在模拟器中,vc加载完美,我也可以单击故事板上的按钮,并在viewController中实现的警报窗口出现。

但是在设备上我的捆绑包甚至都没有加载!

[捆绑加载]之前的NSLog给了我:

Storyboard with relative path bundle path: NSBundle </var/containers/Bundle/Application/2FAD31A9-F6FD-4B74-9596-22336A8216DD/OCRModuleSubBundle.app/OCRSubBundle.bundle> (not yet loaded)

[捆绑加载]之后的NSLog即使应该加载也完全相同。

在模拟器上,第二个NSLog给了我:

Storyboard with relative path bundle path: NSBundle </Users/cassiel/Library/Developer/CoreSimulator/Devices/69A83C12-6C38-4191-9607-8969367317F9/data/Containers/Bundle/Application/0467B06C-6789-4488-987D-11EBE8BC0B8F/OCRModuleSubBundle.app/OCRSubBundle.bundle> (loaded)

所以这绝对是捆绑未正确加载的问题。

有谁知道这个的原因? 我可能需要创建一个框架才能在设备上使用它吗? 我现在已经多年来一直在敲打这个。

感谢帮忙

0 个答案:

没有答案