代码之家  ›  专栏  ›  技术社区  ›  Curt Rand

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

  •  0
  • Curt Rand  · 技术社区  · 6 年前

    我遵循了一个关于如何处理自定义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应用程序。我收到了错误信息 "this.abc is not a function" 在我的iPhone模拟器上。我是新手,不知道这是为什么。我想当我在我的应用程序中从后台转到前台的时候,可能脚本没有加载或者什么的。

    1 回复  |  直到 6 年前
        1
  •  0
  •   QoP    6 年前

    你得绑起来 handleOpenURL 到你的组件。

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

    具有

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