将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?

查看:52
本文介绍了将webapp添加到主屏幕后,是否可以强制iphone/ipod更新apple-touch-icon?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用所有推荐的safari链接和meta标签创建了一个webapp,例如.

I have created a webapp using all of the recommended link and meta tags for safari, eg.

<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应用程序,然后重新添加它.但是有没有一种方法可以让应用程序知道它需要刷新这些图像,而无需用户删除并重新添加它?

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). It works to remove the webapp from the home screen and re-add it. 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!

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

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. 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.

但是,为了与Apple的命名约定保持一致,只要您希望重新下载图标,就可以简单地将URL变量附加到引用中,然后继续调用图像 apple-touch-icon.png .

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.

我为使此问题自动化(在PHP中)所做的工作是将最后修改的日期/时间附加到图像上.例如:

What I have done to automate this issue (in PHP) is append the last modified date/time to the image. For example:

<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" />

现在,您无需执行任何操作,只需从字面上覆盖图像即可,其他一切都会自动发生.更改图像时,修改的时间将更改,并且不再与用户在缓存中的时间匹配,因此将强制进行新的下载.简单!

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.

这篇关于将webapp添加到主屏幕后,是否可以强制iphone/ipod更新apple-touch-icon?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆