如何通过应用程序在iOS桌面上创建快捷方式 [英] How could I create a shortcut on desktop in iOS through an app

查看:137
本文介绍了如何通过应用程序在iOS桌面上创建快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是我想使用该应用程序在桌面上创建一个带图标的快捷方式,这将允许用户加速访问此应用程序的某些功能。

What do I mean is that I want to use the app to create a shortcut with icon on the desktop which will allow user to speed access some functions of this app.

我怎么能这样做,有什么建议吗?或者任何人都有这方面的经验。

How could I do that, any suggestions? Or anyone have experience with this.

一个例子:
FaceDial

推荐答案

我花了很长时间尝试实施这个功能最近进入了一个应用程序,并想把我在这个主题上找到的一些资源用于拯救别人头疼。这正在成为一种越来越受欢迎的功能,并在Workflow和Facebook的Groups应用程序等主要应用程序中使用。鉴于Workflow现在是一个Apple应用程序,它看起来不像Apple在使用这种技术方面有任何问题。 @jin提供的答案基本上是正确的。该过程如下所示:

I spent a good while trying to implement this functionality into an app recently and wanted to put out some of the resources I found on the subject to save someone else a major headache. This is becoming an increasingly popular feature and is used in major apps like Workflow and Facebook's Groups app. Given that Workflow is now an Apple app, it doesn't look like Apple has any issues with using this technique either. The answer provided by @jin is essentially correct. The process looks something like this:


  1. 为您的应用注册自定义URL方案。创建动态URL链接,如果遵循这些链接,则会链接到您希望快捷方式的内容。目前向iOS跳板添加快捷方式的唯一方法是通过Safari的添加到主屏幕功能。所以我们想要做的是使用Safari来保存我们的应用程序到跳板的自定义URL。诀窍是,你不能只是将你的URL发送到Safari并保存它,因为这样做会导致Safari立即关注链接,用户将永远不会有机会点击添加到主屏幕。因此,为了解决这个问题,您需要在某个地方托管一个Web服务,该网站可以获取您的URL并返回一个base64 URL,您的用户可以将其保存到主屏幕。

  2. 要创建此Web服务,您需要可以远程托管它,这将要求您的用户在线使用,或者将其嵌入到您的应用程序中,这就是Workflow和Facebook Groups所做的事情。对于嵌入式服务器,有一些非常容易使用的选项。如果您正在使用objective-c CocoaHTTP ,如果您使用的是Swift,我建议 Swifter ,这就是我使用的。

  3. 您的网络服务器将会需要显示一个以base64编码格式返回另一个页面的页面,以便用户可以在Web服务器停止运行后使用该快捷方式(显然你不能让嵌入式服务器全天候运行)。编码页面需要检测页面是否以独立模式启动。如果是,那么它应该带你到你的应用程序,否则它应该给你一个页面,用户可以将页面保存到主屏幕。以下是我的html查找服务的示例:

  1. Register a custom URL scheme for your app. Create dynamic URL links that, when followed, lead to content you wish to shortcut to. The only way currently to add a shortcut to the iOS springboard is via Safari's "add to homescreen" function. So what we want to do is use Safari to save our custom URLs that lead to our app to the springboard. The trick is, you can't just send your URL to Safari and save it because doing so will cause Safari to immediately follow the link and the user will never have a chance to hit "Add to homescreen". So to circumvent this issue you'll need to host a web-service somewhere that takes your URL and returns a base64 URL which your user can save to the homescreen.
  2. To create this webservice you can either host it remotely,which will require your user to be online to use, or embed one into your app, which is what Workflow and Facebook Groups does. For embeded servers theres some great fairly easy to use options. If you're using objective-c theres CocoaHTTP and if you're using Swift I'd recommend Swifter, which is what I used.
  3. Your webserver will need to display a page which returns another page in an base64 encoded format so that the user can use the shortcut after the webserver stops running (obviously you can't leave the embedded server running 24/7). The encode page will need to detect if the page was launched in standalone mode. If it was, then it should take you to your app, otherwise it should present you with a page where the user can save the page to the homescreen. Here's a sample of how my html looked for the service:

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


以下是帮助我的主题资源列表(对不起,我没有足够的声誉来包含2个以上的链接......所以你必须复制面食这些):

Here's a list of resources on the topic that helped me out (Sorry, I don't have enough reputation to include more than 2 links... so you'll have to copy pasta these):


  1. 网络服务如何与现场演示配合使用的绝佳示例: https://gist.github.com/FokkeZB / 5899387

  2. 描述流程的另一个堆栈溢出问题:
    https://stackoverflow.com/questions/28042152/ link-to-safari-add-to-home-screen-from-inside-app

  3. Grea t javascript小部件,用于提示用户在Safari中点击添加到主屏幕一次:
    http://cubiq.org/add-to-home-screen

  4. Apple关于自定义URL方案的文档:
    https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ Inter-AppCommunication / Inter-AppCommunication.html

  5. Apple内置方案的文档,这将更好地简化简单任务,即发送电子邮件:
    https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html

  6. 示例显示如何在Javascript中对您的HTML进行base64编码:
    https://stackoverflow.com/questions/9238890/convert-html-to-datatext-html-link-using-javascript

  1. Great example of how the web-service works with a live demo: https://gist.github.com/FokkeZB/5899387
  2. Another stack overflow question describing the process: https://stackoverflow.com/questions/28042152/link-to-safari-add-to-home-screen-from-inside-app
  3. Great javascript widget for prompting the user to hit "Add to homescreen" once in Safari: http://cubiq.org/add-to-home-screen
  4. Apple's documentation on custom URL schemes: https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html
  5. Apple's documention for built in schemes, which will be better for shortcutting simple task i.e. sending an email: https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html
  6. Example showing how to base64 encode your HTML in Javascript: https://stackoverflow.com/questions/9238890/convert-html-to-datatext-html-link-using-javascript

如果有人有任何疑问,请告诉我!

Let me know if anyone has any questions!

这篇关于如何通过应用程序在iOS桌面上创建快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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