4

I have set com.testApp://challenge/:id as deep linking URL. It's working fine if the app is closed and I try to visit this as a URL from the browser. Also, this is only happening for iOS.

But it fails if App is open and I try to visit the above URL from the browser.

I have used this article as reference. Though it has if (Platform.OS === 'android') condition but it didn't help.

Following is my code:

  componentDidMount() {
    Linking.addEventListener('url', this.handleOpenURL);
    Linking.getInitialURL().then(url => {
      this.navigate(url);
    });
  }

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

  handleOpenURL = (event) => {
    if(event){
      this.navigate(event.url);
    }
  }

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

      if (routeName === 'challenge') {
        ChallengeService.find(id).then((challenge) => {
          Actions.challenge({ challenge: challenge });
        });
      };
    }
  }

Following is my AppDelegate.m code

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}

Let me know what I am doing wrong.

Bhaskar Dabhi
  • 841
  • 1
  • 11
  • 28
  • The app is already running, and running the app again through the link is naturally error-prone? – hong developer Jul 19 '19 at 16:29
  • @hongdevelop no, My app is running in the background and suppose if I open above url `com.testApp://challenge/:id` in a browser then it should redirect the user to the app running in the background and should redirect to the particular screen using `navigate` function call but it's not happening. Control is not even coming to `Linking.addEventListener`,`Linking.getInitialURL` so that it can be passed to `navigate` function – Bhaskar Dabhi Jul 22 '19 at 13:55
  • @Bhaskar Dabhi Have u found the fix? am also facing a similar experience. – Muneef M Feb 18 '20 at 10:52

1 Answers1

-2

I had the same problem and I solved it with this

<WebView
    source={{ uri }}
    onShouldStartLoadWithRequest={request => {
    console.log('request :', request);
    return request.url.startsWith(request.url);
    }}
/>
anibalajt
  • 958
  • 6
  • 12