Firebase 从deeplink打开时如何刷新应用程序?
我正在努力使用react原生应用程序。我本想实现react原生firebase动态链接,但现在我有点迷路了。我在主屏幕上使用这种方法,每当有人打开应用程序时,这种方法都能正常工作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";
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);
}
}