我最近花了很多时间尝试将这个功能应用到一个应用程序中,并希望提供一些我在这个主题上找到的资源,以避免让别人头疼.这正在成为一种越来越受欢迎的功能,并在Workflow和Facebook的Groups应用程序等主要应用程序中使用.鉴于Workflow现在是Apple应用程序,Apple看起来并不像使用这种技术有任何问题.@jin提供的答案基本上是正确的.该过程看起来像这样:
您的Web服务器将需要显示一个页面,该页面以base64编码格式返回另一个页面,以便用户可以在Web服务器停止运行后使用该快捷方式(显然您不能让嵌入式服务器全天候运行).编码页面需要检测页面是否以独立模式启动.如果是,那么它应该带你到你的应用程序,否则它应该给你一个页面,用户可以将页面保存到主屏幕.这是我的html如何查找服务的示例:
<!DOCTYPE html>
<html>
<div id="html">
<!DOCTYPE html>
<html>
<head>
<title>Add to Homescreen</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;" name="viewport"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta content="SHORTCUT NAME HERE" name="apple-mobile-web-app-title"/>
<link rel="icon" type="image/png" href="data:image/png;base64, ICON IMAGE DATA"/>
<link rel="apple-touch-icon" href="data:image/png;base64, ICON IMAGE DATA"/>
<link rel="apple-touch-startup-image" href="data:image/png;base64, ICON IMAGE DATA"/>
</head>
<body>
<a id="redirectURL" href="YOUR CUSTOM URL" name = "redirectURL"></a>
<script>
if (window.navigator.standalone) {
var e = document.getElementById('redirectURL');
var ev = document.createEvent('MouseEvents');
ev.initEvent('click', true, true);
e.dispatchEvent(ev);
window.close();
} else {
document.write("<center><h1>Valet</h1><img id=\"imageIcon\" src=\"data:image/png;base64, IMAGE ICON DATA\"></img><h2> Add this page to your homescreen </h2></center>")
}
</script>
</body>
</html>
</div>
<script type="text/javascript">
var html = document.getElementById("html").innerHTML;
html = html.replace(/\s{2,}/g, '')
.replace(/%/g, '%25')
.replace(/&/g, '%26')
.replace(/#/g, '%23')
.replace(/"/g, '%22')
.replace(/'/g, '%27');
var dataURI = 'data:text/html;charset=UTF-8,' + html;
window.location.href = dataURI
</script>
</html>
Run Code Online (Sandbox Code Playgroud)以下是帮助我的主题资源列表(抱歉,我没有足够的声誉来包含2个以上的链接......所以你必须复制这些面食):
https://gist.github.com/FokkeZB/5899387https://stackoverflow.com/questions/28042152/link-to-safari-add-to-home-screen-from-inside-apphttp://cubiq.org/add-to-home-screenhttps://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.htmlhttps://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.htmlhttps://stackoverflow.com/questions/9238890/convert-html-to-datatext-html-link-using-javascript如果有人有任何问题,请告诉我!
除了您的应用程序之外,您不能将图标添加到“桌面”(跳板)。这个应用程序正在做的是在他们的应用程序中显示 iPhone“桌面”的副本。
更新:该链接现在指向一个执行此操作的应用程序,尽管在我看来它是 hack,但似乎有些可能。
这就是我相信应用程序的工作方式(它类似于下面的答案,但更详细)。
你可以实现类似的东西(虽然我不建议这样做)。这些是要遵循的步骤:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
注意:如果您的应用程序被删除,webclips 将不再起作用,并且会使用户感到困惑。Apple 也可能会拒绝您的应用。
| 归档时间: |
|
| 查看次数: |
15244 次 |
| 最近记录: |