是否可以使用自定义网址方案打开原生iOS应用程序,而不会将网页指向自定义网址?

时间:2021-09-26 22:10:00

I am trying to open an Native iOS app by clicking a link in email. I had used "Custom url scheme". If i type "test://" in safari browser then my native iOS app is opened. But if i click a link "test://" in email then it prefixed with http like "http://test//" and its not opening an iOS App. 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. Is it possible to open an app from email link without using a webpage redirects to app?

我正在尝试通过单击电子邮件中的链接来打开Native iOS应用程序。我曾经使用过“自定义网址方案”。如果我在safari浏览器中输入“test://”,那么我的原生iOS应用程序就会打开。但是,如果我点击电子邮件中的“test://”链接,那么它的前缀为http,如“http:// test //”,而不是打开iOS应用程序。我经历了很多链接,发现“iOS需要一个网页,它将重定向到原生iOS App的自定义网址”来打开一个应用程序。是否可以在不使用网页重定向到应用程序的情况下从电子邮件链接打开应用程序?

Advance, Thanks for any help !

提前,谢谢你的帮助!

1 个解决方案

#1


2  

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.

简单的答案可能是否定的,因为您无法控制各个应用程序如何处理链接。复杂的答案是你应该对此采取一些措施。请注意,它并不总是需要返回完整的网页 - 在Android上使用Chrome,您可以直接触发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. This can be achieved using the following mechanisms:

或者更好的是,如果应用程序不存在,您可以尝试在iframe中打开URI方案,然后回退到Web URL。这可以使用以下机制来实现:

  1. on iOS 9, use Universal Links
  2. 在iOS 9上,使用Universal Links
  3. in Chrome (and soon, Firefox 41.0!) use Chrome Intents
  4. 在Chrome中(很快,Firefox 41.0!)使用Chrome Intents
  5. on all other browsers, use client-side javascript
  6. 在所有其他浏览器上,使用客户端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. We're constantly dealing with changes to browsers and webviews because there are always new scenarios to cover. It's essential to look at the user agent string when deciding how to deeplink a user into your app.

这正是我们在我的公司branch.io所做的。我们一直在处理浏览器和网页浏览的变化,因为总会有新的方案需要覆盖。在决定如何将用户深入链接到应用程序时,查看用户代理字符串至关重要。

#1


2  

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.

简单的答案可能是否定的,因为您无法控制各个应用程序如何处理链接。复杂的答案是你应该对此采取一些措施。请注意,它并不总是需要返回完整的网页 - 在Android上使用Chrome,您可以直接触发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. This can be achieved using the following mechanisms:

或者更好的是,如果应用程序不存在,您可以尝试在iframe中打开URI方案,然后回退到Web URL。这可以使用以下机制来实现:

  1. on iOS 9, use Universal Links
  2. 在iOS 9上,使用Universal Links
  3. in Chrome (and soon, Firefox 41.0!) use Chrome Intents
  4. 在Chrome中(很快,Firefox 41.0!)使用Chrome Intents
  5. on all other browsers, use client-side javascript
  6. 在所有其他浏览器上,使用客户端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. We're constantly dealing with changes to browsers and webviews because there are always new scenarios to cover. It's essential to look at the user agent string when deciding how to deeplink a user into your app.

这正是我们在我的公司branch.io所做的。我们一直在处理浏览器和网页浏览的变化,因为总会有新的方案需要覆盖。在决定如何将用户深入链接到应用程序时,查看用户代理字符串至关重要。