16

我使用所有推荐的 safari 链接和元标记创建了一个 webapp,例如。

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-startup-image" href="/startup.png" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" /> 
<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-ipad.png" /> 
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-iphone4.png" />

但是,我的问题是,如果 startup.png 或任何 apple-touch-icon 图像文件在网络服务器上更新,用户的 iphone 或 ipod 似乎不会在将更新后的文件保存到他们的主屏幕(我猜它以某种方式缓存)。它可以从主屏幕中删除 web 应用程序并重新添加它。但是有没有办法让应用程序知道它需要刷新这些图像而不需要用户删除并重新添加它?

4

6 回答 6

22

自从提出/回答这个问题以来已经有几年了,我在这里报告这现在是可能的!

在更新的 iOS 版本中,显示在主屏幕上的 Apple Touch 图标会像网站上的任何其他内容一样被缓存。通过简单地更改图像的名称,它将强制主屏幕快捷方式在下次启动快捷方式时刷新图标。

但是,为了符合 Apple 的命名约定,只要您希望重新下载图标并继续调用 image ,您只需将 URL 变量附加到引用中即可apple-touch-icon.png

我为自动处理这个问题(在 PHP 中)所做的是将上次修改的日期/时间附加到图像中。例如:

<link rel="apple-touch-icon" href="apple-touch-icon.png?m=<?php echo filemtime('apple-touch-icon.png'); ?>" />

这输出:

<link rel="apple-touch-icon" href="apple-touch-icon.png?m=1415832495" />

现在,您无需执行任何操作,只需从字面上覆盖图像,其他所有操作都会自动发生。当您更改图像时,修改时间会更改并且不再匹配用户在缓存中的内容,因此它会强制重新下载。简单的!


旧答案:我已经对此进行了大量研究,试图找到一种方法。不幸的是,这是不可能的。需要将其删除并重新添加到主屏幕才能使用新图标。

于 2011-01-03T20:09:51.823 回答
2

I just tested a theory on the Iphone 5 and Ipad 2, and it worked for both. Similar to the favicon, you can force the new favicon to pull by changing the href. Instead of href="/apple-touch-icon.png" I used href="/apple-touch-icon.png?ver=1.1" and it pulled the new icon when the site was visited (without deleting and re-adding to home screen).

于 2014-10-28T14:01:03.010 回答
1

只会添加我的小“解决方法”。已尝试对我的网站进行各种更正,以使该图标正确显示在我自己 IPAD 上的书签中。后来发现在之前访问过我网站的苹果产品上,ICON 显示得很好。我对我网站的所有访问都是http://mysitename(ref).dk但是当我添加http://www.mysitename(ref).dk时,IPAD 终于发现这是一个新网站,并且苹果图标位于在我的书签中正确显示。:-) 雅各布

于 2019-10-06T18:06:37.137 回答
0

我已经看到图标更新了,但我认为不会以任何方式影响此更新。我注意到手机重新启动后更新的图标,但我没有足够的研究来说出任何结论。

于 2011-04-23T16:45:35.433 回答
0

Within my webapp if i just change the startup.png file with a new one, the first time a reload the app from the home screen it shows the old image. Closing and reopening the app shows the new startup.png image. iOS 4.2.1. By the way, the same apllies for the icon.

于 2012-03-06T00:48:25.183 回答
-1

将网页/网络应用程序删除并重新添加到主屏幕可能还不够。我只是想

  1. 从主屏幕删除书签
  2. reload the page in safari
  3. add the bookmark to homescreen

==> it still shows the old icon it seems to have cached somewhere :(

于 2011-08-13T12:40:48.500 回答