firebase动态链接与react-navigation

时间:2018-05-14 10:40:22

标签: android firebase react-native firebase-dynamic-links react-native-firebase

我已遵循此文档https://rnfirebase.io/docs/v4.1.x/links/android并能够运行adb shell am start -W -a android.intent.action.VIEW -d "https://abc123.app.goo.gl" com.myapp.superapp来启动该应用。

如何打开动态链接https://abc123.app.goo.gl打开VideoScreen并传递contentparam

Video:{
  screen : VideoScreen,
  path:'wvc/:contentparam',
}

所以我在点击https://abc123.app.goo.gl(动态链接)时尝试了这一点:

componentDidMount () {
    Linking.getInitialURL().then((url) => {
      console.log('Initial url is: ' + url);
    }).catch(err => console.error('An error occurred', err));
}

然而,应用已打开,console.lognull

2 个答案:

答案 0 :(得分:1)

由于某些原因,firebase.links().onLink((url)在RNFB v6中不起作用。 这是来自RNFB维护者之一的对此bug的评论 https://github.com/invertase/react-native-firebase/issues/3008

使用方法应改用react native Link作为临时解决方法: https://facebook.github.io/react-native/docs/0.47/linking

以下是您可以使用的示例:

  useEffect(() => {
    Linking.getInitialURL()
      .then(url => {
        if (url) {
          console.log('Initial url is: ' + group);
        }
      })
      .catch(err => console.error('An error occurred', err));
  }, []);

答案 1 :(得分:0)

You have to listen to firebase links

componentDidMount() {
  const unsubscribe = firebase.links().onLink((url) => {
    console.log('dynamic links', url)
    // do navigate with url above
    // you have to handle your self
  });
}

componentWillUnmount() {
  unsubscribe()
}

docs: https://rnfirebase.io/docs/v5.x.x/links/reference/links#onLink

相关问题
最新问题