diff --git a/ios/MBXAppDelegate.m b/ios/MBXAppDelegate.m index aa048ca67..0fbcc6e81 100644 --- a/ios/MBXAppDelegate.m +++ b/ios/MBXAppDelegate.m @@ -21,15 +21,4 @@ return YES; } -- (void)applicationDidEnterBackground:(UIApplication *)application -{ - [(MBXViewController *)self.window.rootViewController saveState]; -} - -- (void)applicationWillEnterForeground:(UIApplication *)application -{ - [(MBXViewController *)self.window.rootViewController restoreState]; -} - - -@end \ No newline at end of file +@end diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index a8e710f31..9c4b5d2fe 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -36,6 +36,19 @@ MBXViewController *viewController = nullptr; #pragma mark - Setup +- (id)init +{ + self = [super init]; + + if (self) + { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState) name:UIApplicationDidEnterBackgroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restoreState) name:UIApplicationWillEnterForegroundNotification object:nil]; + } + + return self; +} + - (void)loadView { [super loadView]; @@ -252,6 +265,8 @@ MBXViewController *viewController = nullptr; - (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + if (settings) { // Save settings