Cordova Firebase 身份验证第 7 步“通用链接”

Cordova Firebase Authentication Step 7 " universal-links "

我按照步骤一一进行here。但是第7步出现问题

第 7 步:

<universal-links>
    <host name="DYNAMIC_LINK_DOMAIN" scheme="https" />
    <host name="AUTH_DOMAIN" scheme="https">
        <path url="/__/auth/callback"/>
    </host>
</universal-links>

加config.xml时,"cordova run android"不起作用

Config.xml :

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.twobuddy.hybrtnkk" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>NeKadarKaldi</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <preference name="AndroidLaunchMode" value="singleTask" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <plugin name="cordova-plugin-x-socialsharing" spec="^5.4.0" />
    <plugin name="cordova-plugin-buildinfo" spec="^2.0.1" />
    <plugin name="cordova-plugin-browsertab" spec="^0.2.0" />
    <plugin name="cordova-plugin-inappbrowser" spec="^3.0.0" />
    <plugin name="cordova-plugin-customurlscheme" spec="^4.3.0">
        <variable name="URL_SCHEME" value="com.twobuddy.hybrtnkk" />
        <variable name="ANDROID_SCHEME" value=" " />
        <variable name="ANDROID_HOST" value=" " />
        <variable name="ANDROID_PATHPREFIX" value="/" />
    </plugin>

<universal-links>
    <host name="DYNAMIC_LINK_DOMAIN" scheme="https" />
    <host name="AUTH_DOMAIN" scheme="https">
        <path url="/__/auth/callback"/>
    </host>
</universal-links>

    <plugin name="cordova-universal-links-plugin" spec="^1.2.1" />
    <engine name="ios" spec="^4.5.4" />
    <engine name="android" spec="^7.0.0" />
</widget>

尝试使用通用链接插件的修改版本。可以在这里找到 https://github.com/walteram/cordova-universal-links-plugin

使用 cordova plugin add https://github.com/walteram/cordova-universal-links-plugin.git

安装

这对我有用!

我在这里找到了答案https://github.com/nordnet/cordova-universal-links-plugin/issues/133

我正在使用 PhoneGap Build。问题是通用链接标签没有复制到 AndroidManifest.xml。所以解决方案是

  1. 安装 cordova-universal-links-plugin-fix
  2. 如果您想在 config.xml 中保留通用链接标签,请保留它。但还要将此添加到 config.xml

在顶部的小部件标签中添加

xmlns:android="http://schemas.android.com/apk/res/android"

添加以下代码 在 config.xml 的任意位置我更喜欢在插件之前或在 unvirsal-links 标签旁边

<config-file target="AndroidManifest.xml" parent="/manifest/application/activity">
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:host="****-***.firebaseapp.com" android:pathPrefix="/__/auth/callback" android:scheme="https" />
    </intent-filter>
</config-file>

现在,当使用 phonegapbuild 或本地 cordova CLI 构建应用程序时,它会复制本应位于清单文件中的通用链接数据。当应用程序运行并调用 firebase.auth().getRedirectResult() 时,它不会给出类似

的任何错误

auth/cancelled 按用户。重定向在完成之前被用户取消

使用 cordova CLI 构建应用程序的用户请在 运行 cordova build android 之后确保清单文件中的 activity 标签下有上述 intent-filter 标签。