Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Release graphics when app entered to background mode

In Apple documentation you can find that Apple recommends to release heavy data like images when your app is entering to background mode.
How to release images from UIViews and an other data?
How to release images from UIViews from all viewController right way?
How to restore data when app get applicationWillResignActive message?

If somebody have a good example or link, please show it.

like image 359
rowwingman Avatar asked Jan 25 '26 13:01

rowwingman


1 Answers

Add to app delegate 2 methods

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_BACKGROUND object:nil];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_BACKGROUND object:nil];
}

Make BaseViewController with methods:

- (id)init
{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillForeground) name:NOTIFICATION_APP_FOREGROUND object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBackground) name:NOTIFICATION_APP_BACKGROUND object:nil];
    }

    return self;
}


- (void)appDidBackground {
}

- (void)appWillForeground {

}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

Subclass all your view controllers from BaseViewController. In method appDidBackground you should release unneeded data, in appWillForeground - restore it

like image 72
NeverBe Avatar answered Jan 28 '26 06:01

NeverBe