![](/img/trans.png)
[英]Deeplink: How to redirect user to a website when app is not installed instead of playstore
[英]How to refresh app when opened from deeplink?
我正在努力使用本機應用程序。 我會實現React Native Firebase動態鏈接,但是現在我有點迷路了。 我在HomeScreen上使用此方法,每次有人打開應用程序時,它都能完美運行。
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
以免阻塞初始(第一個)渲染。
您可以使用AppState
偵聽在后台/前景中放置的應用程序的更改。
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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.