0

I have followed a tutorial on how to handle a custom URL scheme. This is the way I have it set up.

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 function is being called, but function abc isn't. I click on a today widget button which opens my app with a custom URL from background to foreground. I am getting the error message "this.abc is not a function" on my iPhone simulator. I am new to react native and not sure why this is. I think maybe the script hasn't loaded or something when I go from background to foreground in my app.

Curt Rand
  • 1,025
  • 1
  • 9
  • 27

1 Answers1

0

You have to bind handleOpenURL to your component.

Replace

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

with

handleOpenURL = (event) => {
   console.log(event.url);
   this.abc()
}
QoP
  • 27,388
  • 16
  • 74
  • 74