简体   繁体   English

一旦将webapp添加到主屏幕,是否可以强制iphone / ipod更新apple-touch-icon?

[英]Is it possible to force iphone/ipod to update apple-touch-icon once webapp is added to home screen?

I have created a webapp using all of the recommended link and meta tags for safari, eg. 我使用了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" />

However, my issue is if the startup.png or any of the apple-touch-icon image files are updated on the webserver, it doesn't seem like a user's iphone or ipod will retreive the updated file once it has been saved to their home screen (I'm guessing it's cached somehow or something). 但是,我的问题是如果在网络服务器上更新了startup.png或任何apple-touch-icon图像文件,它似乎不会是用户的iphone或ipod一旦保存到他们的主屏幕(我猜它是以某种方式缓存的)。 It works to remove the webapp from the home screen and re-add it. 它可以从主屏幕中删除webapp并重新添加。 But is there a way to let the application know it needs to refresh these images without requiring the user to delete and re-add it? 但有没有办法让应用程序知道它需要刷新这些图像而不需要用户删除并重新添加它?

It's been a few years since this question was asked/answered and I'm here to report that this is now possible! 问这个问题已经过了几年,我在这里报告说现在可以了!

In newer iterations of iOS, the Apple Touch Icon that is displayed on the homescreen is cached just like any other piece of content from the website. 在iOS的较新版本中,主屏幕上显示的Apple Touch图标就像网站上的任何其他内容一样被缓存。 By simply changing the name of the image, it will force the homescreen shortcut to refresh the icon the next time the shortcut is launched. 通过简单地更改图像的名称,它将强制主屏幕快捷方式在下次启动快捷方式时刷新图标。

However, to keep in line with Apple's naming conventions, you can simply append URL variables to the reference whenever you want the icon to be redownloaded and continue to call the image apple-touch-icon.png . 但是,为了与Apple的命名约定保持一致,只要您想要重新加载图标并继续调用图像apple-touch-icon.png ,您就可以简单地将URL变量附加到引用。

What I have done to automate this issue (in PHP) is append the last modified date/time to the image. 我所做的自动化此问题(在PHP中)是将最后修改的日期/时间附加到图像。 For example: 例如:

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

This outputs: 这输出:

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

Now, you don't have to do anything but literally overwrite the image and everything else will happen automatically. 现在,您不必做任何事情,只需字面覆盖图像,其他一切都将自动发生。 When you change the image, the modified time changes and doesn't match what the user has in cache anymore, so it forces a new download. 当您更改图像时,修改的时间会更改,并且不再与用户在缓存中的内容相匹配,因此会强制进行新的下载。 Simple! 简单!


OLD ANSWER: I've done a ton of research into this trying to find a way. 老回答:我已经做了大量的研究,试图找到一种方法。 Unfortunately, it is not possible. 不幸的是,这是不可能的。 It needs to be removed and re-added to the home screen for the new icon to be used. 需要将其删除并重新添加到主屏幕,以便使用新图标。

I just tested a theory on the Iphone 5 and Ipad 2, and it worked for both. 我刚刚在Iphone 5和Ipad 2上测试了一个理论,它适用于两者。 Similar to the favicon, you can force the new favicon to pull by changing the href. 与favicon类似,您可以通过更改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). 而不是href="/apple-touch-icon.png"我使用了href="/apple-touch-icon.png?ver=1.1"并在访问网站时拉出了新图标(没有删除和重新添加到主屏幕)。

I've seen icons get updated, but I don't think it's possible to affect this update in any way. 我已经看到图标得到更新,但我认为不可能以任何方式影响此更新。 I've noticed the updated icons after the phone was rebooted, but I haven't look enough into it to say anything conclusive. 手机重启后我已经注意到了更新的图标,但是我还没有看到足够的结论。

Removing and re-adding the webpage/webapp to the homescreen may not even suffice. 删除并重新添加网页/ webapp到主屏幕可能甚至不够。 I just tried to 我只是试着

  1. delete the bookmark from homescreen 从主屏幕删除书签
  2. reload the page in safari 在safari中重新加载页面
  3. add the bookmark to homescreen 将书签添加到主屏幕

==> it still shows the old icon it seems to have cached somewhere :( ==>它仍然显示它似乎缓存在某处的旧图标:(

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. 在我的webapp中,如果我只是用一个新文件更改startup.png文件,第一次从主屏幕重新加载应用程序时它会显示旧图像。 Closing and reopening the app shows the new startup.png image. 关闭并重新打开应用程序会显示新的startup.png图像。 iOS 4.2.1. iOS 4.2.1。 By the way, the same apllies for the icon. 顺便说一下,图标的相同apllies。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM