The easiest way to clear UIWebview
cache is:
Objective-C
[[NSURLCache sharedURLCache] removeAllCachedResponses];
Swift
NSURLCache.sharedURLCache().removeAllCachedResponses()
Now, for your case, you may want to use this function after
calculating proper date:
Clears the given cache of any cached responses since the provided date.
*/
@available(iOS 8.0, *)
public func removeCachedResponsesSinceDate(date: NSDate)
A good scenario would be:
1.- Store the last time/date you cleaned cache (or first time the app is used) in NSUserDefaults
.
2.- Every time you enter your app (or in background fetch
) calculate if has being 24h or more since that date
3.- If true
, then clear cache and return to step 1