本文介绍了如何使用NFC重定向到或打开我的Progressive Web App?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个渐进式网络应用程序,app.example.com是使用Android上的Chrome的添加到主屏幕"按钮创建的.

I've got a progressive web app, app.example.com created using Chrome's "Add to Home Screen" button on Android.

我有一个NFC标签,当点击它时,通常会在Chrome中打开app.example.com/nfc_app.

I have an NFC tag that ordinarily opens app.example.com/nfc_app in Chrome when it's tapped.

我该如何做才能让NFC标签在点击时打开app.example.com/nfc_app PWA而不是Chrome?

How can I make it so that this NFC tag opens up the app.example.com/nfc_app PWA instead of Chrome when tapped?

推荐答案

可以确认,Android 8,其他网站或其他应用程序上的链接可以正常打开PWA,但NFC意图可以打开Chrome.这是另一种不需要您安装本机助手APK的解决方法:

Can confirm, Android 8, links on other websites or from other apps open the PWA just fine, but the NFC intent opens Chrome. Here is another workaround that doesn't require you to install a native helper APK:

创建一个简单的重定向HTML文件pwa.html并从其他域提供它,例如other.example.com:

Create a simple redirect HTML file pwa.html and serve it from a different domain, let's say other.example.com:

<html>
    <body><a id="link"></a></body>
    <script type="text/javascript">
        var a = document.getElementById('link');
        // set the target link as desired, may add routes and params etc.
        a.href = "https://app.example.com/...";
        a.click();
    </script>
</html>

然后,您无需将NFC标记指向https://app.example.com,而是对其进行编程以使其指向重定向HTML https://other.example.com/pwa.html.它不是完美的,实际上只是一种解决方法,但是比构建和安装单独的APK更简单.

Then, instead of having the NFC tag point to https://app.example.com, you would program it to point to your redirect HTML https://other.example.com/pwa.html. It's not perfect and really just a workaround, but simpler than building and installing a separate APK.

这篇关于如何使用NFC重定向到或打开我的Progressive Web App?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:58