React Native:这不是处理自定义 URL 方案的函数

React Native: This is not a function handling custom URL scheme

我遵循了有关如何处理自定义 URL 方案的教程。我就是这样设置的。

componentDidMount() {
    Linking.addEventListener('url', this.handleOpenURL);
  }

componentWillUnmount() {
   Linking.removeEventListener('url', this.handleOpenURL);
  }

handleOpenURL(event) {
   console.log(event.url);
   this.abc()
  }

 abc() {
   console.log("Hello World");
 }
正在调用

handleOpenUrl 函数,但未调用函数 abc。我点击一个今天的小部件按钮,它打开我的应用程序,从后台到前台使用自定义 URL。我在 iPhone 模拟器上收到错误消息 "this.abc is not a function"。我是新来的本地人,不知道为什么会这样。我想当我在我的应用程序中从后台转到前台时,脚本可能没有加载或发生了什么。

您必须将 handleOpenURL 绑定到您的组件。

替换

handleOpenURL(event) {
   console.log(event.url);
   this.abc()
}

handleOpenURL = (event) => {
   console.log(event.url);
   this.abc()
}