我有一个带有故事板和控制器类的库,用于实现 iOS 状态保存。
要从主应用程序的委托启动库,我使用以下命令:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
[self.window makeKeyAndVisible];
self.window.rootViewController = myLibrary.sharedInstance.firstController;
return YES;
}
然后在我的库中,firstController 是使用以下命令创建的:
- ( UIViewController * _Nullable ) firstController
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"libraryMain"
bundle:[NSBundle bundleForClass:self.class]];
return [storyboard instantiateViewControllerWithIdentifier:@"firstController"];
}
到目前为止,一切都很好。它启动库的视图控制器,该控制器使用库的“libraryMain”故事板。
在主应用程序的委托中,我还添加了shouldSaveApplicationState和shouldRestoreApplicationState,两者都返回YES。
当我的应用程序进入后台时,iOS 在委托中正确调用 shouldSaveApplicationState 并继续调用库控制器的encodeRestorableStateWithCoder 方法。
但是,当它尝试恢复时,iOS 正确调用主应用程序委托的 shouldRestoreApplicationState 方法,但随后立即崩溃,并出现以下异常:
Exception occurred restoring state Could not find a storyboard named 'libraryMain' in bundle ... Main App.app
因此,iOS 正在主应用程序包中寻找库Main Storyboard。如何让 iOS 查看库的捆绑包?或者是不可能在 iOS 库中实现状态恢复?
Thanks!