Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 从deeplink打开时如何刷新应用程序?_Firebase_React Native_Firebase Dynamic Links - Fatal编程技术网

Firebase 从deeplink打开时如何刷新应用程序?

Firebase 从deeplink打开时如何刷新应用程序?,firebase,react-native,firebase-dynamic-links,Firebase,React Native,Firebase Dynamic Links,我正在努力使用react原生应用程序。我本想实现react原生firebase动态链接,但现在我有点迷路了。我在主屏幕上使用这种方法,每当有人打开应用程序时,这种方法都能正常工作 async componentWillMount() { try { let url = await firebase.links().getInitialLink(); if(url) { let api = "example.com/user/123456";

我正在努力使用react原生应用程序。我本想实现react原生firebase动态链接,但现在我有点迷路了。我在主屏幕上使用这种方法,每当有人打开应用程序时,这种方法都能正常工作

async componentWillMount() {
    try {
      let url = await firebase.links().getInitialLink();
      if(url) {
        let api = "example.com/user/123456";
        try {
          this.setState({ data: "John Doe" });
          this.props.navigation.navigate('Preview', {user: this.state.data })
        }
        catch {
        }
      }
    }
    catch {
    }
  }

但当应用程序已经打开时,此方法无法正常工作。有没有一种方法可以让我在每次有人返回打开的应用程序时触发一个函数?

提示一下,您应该将代码放在componentDidMount中,这样您就不会阻止最初的第一次渲染

你可以用来监听后台/前台应用程序的更改

componentDidMount() {
  this.showPreview();
  AppState.addEventListener('change', this.onAppStateChange);
}

componentWillUnmount() {
  AppState.removeEventListener('change', this.onAppStateChange);
}

const onAppStateChange = appState => {
  // You can check if appState is active/background/foreground
  this.showPreview();
}

const showPreview = async (appState) => {
    // You can check if appState is active/inactive/background
    try {
      let url = await firebase.links().getInitialLink();
      if(url) {
        let api = "example.com/user/123456";
        try {
          this.setState({ data: "John Doe" });
          this.props.navigation.navigate('Preview', {user: this.state.data })
        }
        catch {
        }
      }
    }
    catch(e) {
      console.error(e);
    }
}