Last active
March 3, 2018 17:25
-
-
Save alansvits/add1fe47b6b92518967e33d1e3da95d4 to your computer and use it in GitHub Desktop.
Saving some data from applicationDidEnterBackground method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Put the code in the class that actually has the data. Have the class register for the UIApplicationDidEnterBackgroundNotification notification. | |
// Put this in the `init` method | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgrounding) name:UIApplicationDidEnterBackgroundNotification object:nil]; | |
// The method that gets called | |
- (void)backgrounding { | |
// save the data | |
} | |
// Put this in the `dealloc` method | |
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; | |
With this setup you don't have to get anything into the UIApplicationDelegate and the responsibility is kept where it belongs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment