简体   繁体   English

如何在前台刷新原生 Deeplink 应用程序?

[英]How to Refresh Native Deeplink Application When In Foreground?

I have a problem when I use deep linking android on react native.当我在 React Native 上使用深度链接 android 时遇到问题。 And when the application is in a foreground state when the application is triggered from deep-linking the application does not refresh on that screen.当应用程序处于前台状态时,当应用程序从深层链接触发时,该应用程序不会在该屏幕上刷新。 For example, I want deep linking to the Home Screen but when my foreground is on the profile screen then my application doesn't refresh?例如,我想要深度链接到主屏幕,但是当我的前景在个人资料屏幕上时,我的应用程序不会刷新?

this my code for deeplinking :这是我的深层链接代码:

  async componentDidMount() {
    //  This for deeplinking
    if (Platform.OS === 'android') {
      Linking.getInitialURL().then(url => {
        this.navigate(url);
      });
    } else {
      Linking.addEventListener('url', this.handleOpenURL);
    }
  navigate = (url) => {
    const { navigate } = this.props.navigation;

    const route = url.replace(/.*?:\/\//g, '');
    const id = route.match(/\/([^\/]+)\/?$/)[1];
    const routeName = route.split('/')[0];
    if (id === 'yes') {
      alert(id)
    }
  }

We can use property from react native firebase, which can detect app in foreground, background nor in app.我们可以使用来自 react native firebase 的属性,它可以在前台、后台或应用程序中检测应用程序。 documentation if you used notification for your app.如果您为您的应用程序使用了通知,则文档 And if you not you can use didFocus() from react navigation.如果你没有,你可以使用来自反应导航的didFocus()

I was having the same issue and this StackOverflow answer solved it for me: https://stackoverflow.com/a/59351886/5901486我遇到了同样的问题,这个 StackOverflow 答案为我解决了这个问题: https : //stackoverflow.com/a/59351886/5901486

To quote Michael引用迈克尔

Finally I figured it out, Linking.addEventListener('url', callback) returns and event, to get the url it should be event.url, what I did before is Linking.addEventListener('url',(url) => setLink(url)) which must be Linking.addEventListener('url',({ url }) => setLink(url))最后我想通了,Linking.addEventListener('url', callback) 返回和事件,要获取 url 应该是 event.url,我之前做的是 Linking.addEventListener('url',(url) => setLink (url)) 必须是 Linking.addEventListener('url',({ url }) => setLink(url))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM