React Native:在特定的深层链接打开推送通知 URL

React Native: Opening a push notification at a specific deeplink URL

我正在尝试通过推送通知在特定屏幕上打开应用程序。我的理解是,我使用了一个“deep link”来做到这一点。我已经设置了反应导航来处理深度 link(以及 AndroidManifest.xml 和 appDelegate.m),并且可以使用 xcrun simctl openurl booted myapp://a/1 / [ 打开深度 link =12=].

但是当应用程序关闭时,我无法收到打开应用程序的推送通知,在深处link;它只会在主屏幕上打开应用程序(在 iOS 和 Android 上)。如何让应用程序在深层打开 link(或者读取推送通知的内容以便我自己导航到正确的屏幕)?

库版本:

经过一些调试,我发现它实际上是我的代码处理通知的问题。我正在检查通知正文中的 ID 属性,但并非所有通知都有。所以一旦我删除它,它就开始工作了。所以要让它工作,你应该有这样的东西:

// push handler component
class PushHandler extends React.Component {
  componentDidMount() {
    FCM.getInitialNotification(notification => {
      if (!notification) {
        // the app was not opened with a notification.
        return;
      }

      // extract route from `notification` here

      this.props.navigation.navigate(route);
    }
  }

  // ... rest of push notification handling code
}

它也与深层链接没有任何关系。 this.props.navigation.navigate 只是普通的 in-app 导航。