Last Updated: February 25, 2016
·
4.267K
· mattgambo

Clear your application cache

This is my first share, and I'm sharing it because it took me a while to find it. If you ever need to clear you application cache, which is quite common for us here since we cache a lot of images in the QThru app, simply put this single line in your app delegate:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

I recommend you call this in any cleanup steps you have that prepare the app for a fresh installation, whether on app deletion or first time app use.

For example:

// This flag checks for a fresh installation of the app.  If it is a fresh installation, do important stuff like clearing the previous PIN
BOOL isNotFirstTimeRun = [[NSUserDefaults standardUserDefaults] boolForKey:IS_NOT_FIRST_TIME_RUN];

if (!isNotFirstTimeRun) {
    // Delete Keychain items

    // Clear the cache if this is a first time run
    [[NSURLCache sharedURLCache] removeAllCachedResponses];

    // Set the flag to true and synchronize the user defaults
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setBool:YES forKey:IS_NOT_FIRST_TIME_RUN];
    [defaults synchronize];
}

1 Response
Add your response

For iPhone users, you can try this way.

http://www.youtube.com/watch?v=4ILHNHJvJkA

over 1 year ago ·