I have a library with a storyboard and controller classes that implement iOS state preservation.
To launch the library from the main app's delegate, I use the following:
- (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;
}
Then inside my library, firstController is created with:
- ( UIViewController * _Nullable ) firstController
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"libraryMain"
bundle:[NSBundle bundleForClass:self.class]];
return [storyboard instantiateViewControllerWithIdentifier:@"firstController"];
}
So far so good. It starts the library's view controller that uses the library's "libraryMain" storyboard.
In the main app's delegate, I've also added shouldSaveApplicationState and shouldRestoreApplicationState, both of which return YES.
When my app goes to the background, iOS correctly calls shouldSaveApplicationState in delegate and proceeds to call the library's controller's encodeRestorableStateWithCoder methods.
However, when it tries to restore, iOS correctly calls the main app delegate's shouldRestoreApplicationState method, but then immediately crashes with the following exception:
Exception occurred restoring state Could not find a storyboard named 'libraryMain' in bundle ... Main App.app
So iOS is looking for the libraryMain storyboard in the main app's bundle. How do I get iOS to look in the library's bundle? Or is it just not possible to implement state restoration in an iOS library?
Thanks!