iOS6 - How to Clear Cache of Homescreen/Standalone

2020-05-18 11:34发布

It would appear that Apple have changed the way homescreen/standalone web apps work in iOS 6. According to various blog posts (example) these apps now get their own dedicated space for storing their cached files, sqllite dbs, local storage etc, rather than sharing with the Safari browser like before.

Before iOS 6 when developing I used to go through the following procedure religiously to clear the cache...

  1. Remove app from homescreen.
  2. Close all pages/tabs in Safari.
  3. Finally "Clear Cookies & Data" or "Clear Data" in "Settings" > "Safari".

Unfortunately now that Apple have moved the goal posts this same procedure doesn't seem to work. After clearing, even though my changes are picked up in Safari, when I add to the homescreen and launch the app the old HTML,JS etc is still picked up.

Does anyone know how to reliably fully clear the cache in iOS 6?

9条回答
走好不送
2楼-- · 2020-05-18 11:50

I can't verify the cache being cleared properly but this worked for me :

In order to do this, you need to allow Web Inspector on your iOS device. Go to Settings > Safari > Advanced > Web Inspector (it has to be active) And you have to activate the developer menu on your computer's Safari. Go to Preferences > Advanced > Activate Developer menu

  1. Connect your device to your computer with the USB cable
  2. Go to safari > Developpement > Your Device name > Inspect an App (The app has to be running)
  3. This will open The inspector on your computer for the web app
  4. While the inspector is open Clear the cache (command + alt + E)
  5. With the inspector still open refresh the page on your computer (command + R)

Somehow the Webapp cache got cleared and i got the non-cached code.

查看更多
手持菜刀,她持情操
3楼-- · 2020-05-18 12:01

This drove me nuts for a while. Tried clearing the cache on device - no luck. Renaming the page did help, but once you rename it back, you still get the same stale version. Found the solution yesterday. You need to connect your device to Mac and open Web Inspector in Safari Develop menu. Once in Web Inspector, simply press "Reload page" button on the Inspector's toolbar and - voila - you see the fresh version on your device's screen.

查看更多
迷人小祖宗
4楼-- · 2020-05-18 12:02

Just set the request you pass to the webview to NSURLRequestReloadIgnoringLocalCacheData

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[self.webView loadRequest:request];
查看更多
Juvenile、少年°
5楼-- · 2020-05-18 12:03

Try appending a unique GET tag to the ends of any and all href attributes, for example:

<link rel="stylesheet" type="text/css" href="/css/global.css?
   <?php echo(mt_rand(10000000, 99999999)); ?>
" />

This would generate href="/css/global.css?########", with a different number nearly every time. This forces iOS' Safari to pull the "new" page down, as there is no data in its cache originating from the same URI, and there likely never will be (unless you plan on reloading the app millions of times during development :D )

查看更多
祖国的老花朵
6楼-- · 2020-05-18 12:09

If the iOS6 device has a jailbreak applied, you can use ssh to delete the content of the folder "/private/var/mobile/Library/Caches/com.apple.webapp".

Next time that you start the web app, all files will be re-downloaded from the webserver.

查看更多
等我变得足够好
7楼-- · 2020-05-18 12:10

You can connect your device and open Safari's web inspector on your computer and run document.location.reload() in the console tab to reload the page.

Before reloading you can press Option+Command+E to make sure the cache is cleared.

Instead of above you can also press Shift+Command+R to reload the page without cache but sometimes it hasn't worked for me.

查看更多
登录 后发表回答