One of the mobile apps that I've written has to access a remote site for authentication. This allows the client to make use of multiple factors for confirming a user's identity and also confirms to the user that they're passing their credentials to the right institution.
When the application was originally written, I made use of the ChildBrowser control. In order to make sure that we were seeing the right content only if the user REALLY has authenticated, we would use the ChildBrowser's clear() method.
I was recently asked to update the application to ensure that it didn't lag too far behind the most recent versions of the tools. Updating to Cordova 3.1/PhoneGap 3.1 involved getting rid of the ChildBrowser and moving to the InAppBrowser plugin. PhoneGap makes this plugin REALLY easy to integrate with your project. All you have to do at the command-line is to issue the following command:
cordova plugin add org.apache.cordova.inappbrowser
Unfortunately, once I changed the remainder of the calls around to work with the new interface, I found there was no method to clear the cache. There are options on the Android side of things that will clear the cache as well as the session cache, but nothing on the iOS side.
It didn't take too long to figure out, but here's what I ended up with:
All I added was the one-liner:
[[NSURLCache sharedURLCache] removeAllCachedResponses];This article is cross-posted from the AnexinetMobility Blog