From f8b94bfd6634c53789ee0705c8ef78aadb5c8599 Mon Sep 17 00:00:00 2001 From: Ignacio Romero Zurbuchen Date: Wed, 30 Mar 2016 10:48:44 -0700 Subject: [PATCH] Makes sure to cache text even if the view isn't visible. Also caches text on DidEnterBackground notification. Closes #427 --- Source/SLKTextViewController.m | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Source/SLKTextViewController.m b/Source/SLKTextViewController.m index 675a738b..656e25a7 100644 --- a/Source/SLKTextViewController.m +++ b/Source/SLKTextViewController.m @@ -1561,14 +1561,6 @@ - (void)slk_willShowOrHideTypeIndicatorView:(UIView }]; } -- (void)slk_willTerminateApplication:(NSNotification *)notification -{ - // Caches the text before it's too late! - if (self.isViewVisible) { - [self slk_cacheTextView]; - } -} - #pragma mark - KVO Events @@ -2237,8 +2229,9 @@ - (void)slk_registerNotifications [notificationCenter addObserver:self selector:@selector(slk_didShakeTextView:) name:SLKTextViewDidShakeNotification object:nil]; // Application notifications - [notificationCenter addObserver:self selector:@selector(slk_willTerminateApplication:) name:UIApplicationWillTerminateNotification object:nil]; - [notificationCenter addObserver:self selector:@selector(slk_willTerminateApplication:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; + [notificationCenter addObserver:self selector:@selector(slk_cacheTextView) name:UIApplicationWillTerminateNotification object:nil]; + [notificationCenter addObserver:self selector:@selector(slk_cacheTextView) name:UIApplicationDidEnterBackgroundNotification object:nil]; + [notificationCenter addObserver:self selector:@selector(slk_cacheTextView) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; } - (void)slk_unregisterNotifications @@ -2270,6 +2263,7 @@ - (void)slk_unregisterNotifications // Application notifications [notificationCenter removeObserver:self name:UIApplicationWillTerminateNotification object:nil]; + [notificationCenter removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; [notificationCenter removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; }