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.