简体   繁体   English

是否可以通过使用自定义 url 方案打开本机 iOS 应用程序而无需网页定向到自定义 url?

[英]Is it possible to open an Native iOS app by using Custom url scheme without a webpage directs to custom url?

I am trying to open an Native iOS app by clicking a link in email.我正在尝试通过单击电子邮件中的链接来打开本机 iOS 应用程序。 I had used "Custom url scheme".我使用过“自定义网址方案”。 If i type "test://" in safari browser then my native iOS app is opened.如果我在 safari 浏览器中输入“test://”,那么我的原生 iOS 应用程序就会打开。 But if i click a link "test://" in email then it prefixed with http like " http://test// " and its not opening an iOS App.但是,如果我单击电子邮件中的链接“test://”,那么它会以 http 为前缀,例如“ http://test// ”,并且不会打开 iOS 应用程序。 I went through lot of links and found that "iOS needs a Webpage which will redirect to custom url of native iOS App" to open an app.我浏览了很多链接,发现"iOS needs a Webpage which will redirect to custom url of native iOS App"来打开一个应用程序。 Is it possible to open an app from email link without using a webpage redirects to app?

Advance, Thanks for any help !提前,感谢您的帮助!

The simple answer is likely no, as you have little control over how individual apps will handle links.简单的答案可能是否定的,因为您几乎无法控制单个应用程序将如何处理链接。 The complex answer is that you should do something about it.复杂的答案是你应该做些什么。 Note that it won't always require returning a full web page -- on Android with Chrome you can fire a 307 redirect straight to a Chrome intent.请注意,它并不总是需要返回完整的网页——在带有 Chrome 的 Android 上,您可以直接触发 307 重定向到 Chrome 意图。

You could set up a simple web server that, when pinged, returns `window.location = 'test://'.您可以设置一个简单的 Web 服务器,在 ping 时返回 `window.location = 'test://'。

Or better yet, you can try to open the URI scheme in an iframe then fallback to a web URL if the app isn't present.或者更好的是,如果应用程序不存在,您可以尝试在 iframe 中打开 URI 方案,然后回退到 Web URL。 This can be achieved using the following mechanisms:这可以使用以下机制来实现:

  1. on iOS 9, use Universal Links在 iOS 9 上,使用通用链接
  2. in Chrome (and soon, Firefox 41.0!) use Chrome Intents在 Chrome(很快,Firefox 41.0!)中使用 Chrome Intents
  3. on all other browsers, use client-side javascript在所有其他浏览器上,使用客户端 javascript

Here's an example of client-side javascript:下面是一个客户端 javascript 的例子:

<script type="text/javascript">
    window.onload = function() {
        // Deep link to your app goes here
        document.getElementById("l").src = "my_app://";

        setTimeout(function() {
            // Link to the App Store should go here -- only fires if deep link fails                
            window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8";
        }, 500);
    };
</script>
<iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>

This is exactly what we do at my company, branch.io .这正是我们在我的公司branch.io 所做的 We're constantly dealing with changes to browsers and webviews because there are always new scenarios to cover.我们一直在处理浏览器和 web 视图的变化,因为总是有新的场景需要覆盖。 It's essential to look at the user agent string when deciding how to deeplink a user into your app.在决定如何将用户深层链接到您的应用时,必须查看用户代理字符串。

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

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