【问题标题】:Deeplinking with a domain name使用域名进行深度链接
【发布时间】:2021-05-25 10:04:56
【问题描述】:

我的App.js 中有以下代码:

import React, { useState, useRef, useEffect } from 'react';
import { SafeAreaView, Text } from 'react-native';
import { NavigationContainer, useLinking } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();
const Screen1 = () => <SafeAreaView><Text>Screen1</Text></SafeAreaView>;
const Screen2 = () => <SafeAreaView><Text>Screen2</Text></SafeAreaView>;

export default function App() {
  const ref = useRef();
  const [isReady, setIsReady] = useState(false);
  const [initialState, setInitialState] = useState();
  const { getInitialState } = useLinking(ref, {
    prefixes: ['http://example.com', 'mychat://'],
    config: {
      screens: {
        Screen2: 'screen-2',
      },
    },
  });

  useEffect(() => {
    getInitialState().then((state) => {
      if (state !== undefined) setInitialState(state);

      setIsReady(true);
    });
  }, [getInitialState]);

  if (!isReady) return null;

  return (
    <NavigationContainer ref={ref} initialState={initialState}>
      <Stack.Navigator>
        <Stack.Screen name='Screen1' component={Screen1} />
        <Stack.Screen name='Screen2' component={Screen2} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

大部分都是从https://reactnavigation.org/docs/deep-linking/和https://reactnavigation.org/docs/use-linking/复制过来的。

在文档中有prefixes: ['https://mychat.com', 'mychat://'],我只是将https://mychat.com 更改为http://example.com。但这似乎不起作用。

当我在 Safari 中打开以下链接时:

  • mychat://(有效,被重定向到应用Screen1)
  • mychat://screen-2(有效,被重定向到应用Screen2)
  • http://example.com(只是在浏览器中打开链接,没有弹出重定向到应用程序)

我需要进行哪些更改才能将域名重定向到移动应用程序?我错过了什么吗?

【问题讨论】:

    标签: ios react-native react-navigation deep-linking


    【解决方案1】:

    您需要使用您有权访问的域以及服务器。

    您的服务器需要托管几个文件,通常在 .well-known 目录中:

    • apple-app-site-association(注意不需要.json)
    • assetlinks.json

    您还需要在您的应用中为 iOS 启用一些权利,对于 Android 也可能如此。在 iOS 上,这将启用 Associated Domains 权利以及 webcredentials:yourdomain.com

    的条目

    该文档非常好,可以帮助您了解实现通用链接需要做什么

    例子:

    【讨论】:

    • 我猜appID 和sha256_cert_fingerprints 只会在您将应用发布到 App Store 和 Google Play 时生成?
    • 您将使用您的应用发布密钥库来生成指纹。至于appID,这是您的团队 ID(来自 Apple 开发者控制台),带有一个点,然后是您的包标识符。 123.com.my.app.
    猜你喜欢
    • 2017-04-03
    • 1970-01-01
    • 2021-03-12
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 2019-08-27
    • 2015-08-01
    • 2020-07-27
    相关资源
    最近更新 更多