使用React导航配置Firebase动态链接

icnyk63a  于 2023-01-27  发布在  React
关注(0)|答案(1)|浏览(161)

我很难使用React Navigation配置Firebase动态链接。动态链接成功触发了应用程序。但是,它没有导航到正确的路径(屏幕)我正在用安卓系统,还没有,我开始了(对我来说)更困难的iOS配置。我确信我得到了一个(或多个)配置选项错误。我将非常感谢您的努力和时间来帮助。
以下功能正常工作并导航到正确的路线:
adb shell am start -W -a android.intent.action.VIEW -d casualjob://InvitedEmployee com.casualjob.
以下情况可启动应用程序,但无法导航到正确的路线:
npx uri-scheme open "https://casualjobsyd.page.link/app?link=https%3A%2F%2Fbuildwebsitepro.com.au%2Fcasualjob%2FInvitedEmployee" --android.
链接预览https://casualjobsyd.page.link/app?d=1返回动态链接树成功,下面的命令返回正确的json:https://casualjobsyd.page.link/.well-known/assetlinks.json
Firebase控制台配置:

  • 动态链接名称:https://casualjobsyd.page.link
  • 短动态链接:https://casualjobsyd.page.link/app
  • 深度链接:https://buildwebsitepro.com.au/casualjob

AndroidManifest.xml

...
<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
    android:launchMode="singleTask"
    android:windowSoftInputMode="adjustResize"
    android:exported="true"
>
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="casualjob"/>
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="http"  android:host="casualjobsyd.page.link/app"/>
        <data android:scheme="https" android:host="casualjobsyd.page.link/app"/>
    </intent-filter>
</activity>
...

动态链接是使用以下代码生成的:

const link = await dynamicLinks().buildLink({
    link: "https://buildwebsitepro.com.au/casualjob/", 
    domainUriPrefix: "https://casualjobsyd.page.link/app",
});
const linkSentToUser = link + "InvitedEmployee";
// result of the above is: "https://casualjobsyd.page.link/app?link=https%3A%2F%2Fbuildwebsitepro.com.au%2Fcasualjob%2FInvitedEmployee"

React导航动态链接配置:

const linking = {
    prefixes: ["casualjob://", "https://casualjobsyd.page.link/app", ], 
    config: config,
    async getInitialURL() {
        const { isAvailable } = utils().playServicesAvailability;
        if (isAvailable) {
            const initialLink = await dynamicLinks().getInitialLink(); 
            if (initialLink) {
                return initialLink.url;
            }
        }
        const url = await Linking.getInitialURL(); 
        return url;
    },
    subscribe(listener) {
        const unsubscribeFirebase = dynamicLinks().onLink(({ url }) => {
            listener(url);
        });
        const linkingSubscription = Linking.addEventListener("url", ({ url }) => {
            listener(url);
        });
        return () => {
            unsubscribeFirebase();
            linkingSubscription.remove();
        };
    },
};
egdjgwm8

egdjgwm81#

我想通了。最重要的改变是需要添加每个到Firebase控制台的深度链接。对于上面的例子,我不得不改变以下内容。
Firebase控制台上定义的Deep Link为:https://buildwebsitepro.com.au/casualjob
Firebase控制台上定义的Deep Link应为:https://buildwebsitepro.com.au/casualjob/InvitedEmployee
还需要进行其他更改。

const linking = {
    // The 2nd element below should be changed to look like the following.
    prefixes: ["casualjob://", "https://casualjobsyd.page.link/app", ], 
    // ...
}

我得知我的AndroidManifest.xml是错误的。下面是文档推荐的,尽管看起来没有必要!?

<!-- Note that the android:host must be set to the domain of "your deep link," and NOT the "Dynamic Links" domain -->
<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="https" android:host="buildwebsitepro.com.au" android:pathPrefix="/casualjob/" />
</intent-filter>

<!--  android:autoVerify="true" is required below -->
<!-- Note that the android:host must be set to your "Dynamic Links" domain, and not the domain of "your deep link." -->
<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:scheme="https" android:host="casualjobsyd.page.link/app"/>
    <data android:scheme="http"  android:host="casualjobsyd.page.link/app"/>
</intent-filter>

相关问题