question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deep linking return null via push notification when i kill the app

See original GitHub issue

Current Behavior


// App.js

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

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

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

    this.navigator &&
          this.navigator.dispatch(
            NavigationActions.navigate({
               routeName
               params: {
                 route_id,
               },
             }),
          );
}

i have 2 scenarios in IOS:

  • if the app is already opened and it is in the background, send push notification from intercom with deep link, i receive it then i click on it the app opened and redirect me to the screen that i want.
  • if i kill the app by swipping it, i send the same notifcation, if i click on it, that only open the app no redirection, in this case if i use safari with my app url schema like appname://...., i can open the app and navigate to the disired screen., only from push notification that not work.

Expected Behavior

  • if i kill the app and receive notification with deep link action i can navigate to the desired screen.

Your Environment

software version
iOS 13.3.1
react-navigation ^4.0.10
react-navigation-stack ^1.10.3
react-navigation-tabs ^2.5.6
react-native-reanimated ^1.4.0
react-native-gesture-handler ^1.5.0
react-native-screens ^2.0.0-alpha.11
react-native 0.61.4"
node v13.6.0
yarn 1.21.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:13

github_iconTop GitHub Comments

1reaction
emawbycommented, May 24, 2021

This issue is caused because when launching the app from a notification the launch options will not contain the initial url, and since the React-Native run time is not available yet, the url event listener won’t fire. A fix for this would involve somehow having the event listener work even when the run time hasn’t loaded yet. Otherwise you will need to parse the options in iOS native code for the launch URL and set the launch option key that react native is looking for.

1reaction
cx5168commented, Aug 17, 2020

follow: #5047 solved it!

Can you explain us the solution ? Last comment is same code as provided on this issue (listener + getInitialURL).

I notice that it seems working when dev server is not used (bundle file instead of bridge url).

my solution: node_modules/react-native/Libraries/LinkingIOS/RCTLinkingManager.m

getInitialURL:

RCT_EXPORT_METHOD(getInitialURL:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject) { NSURL *initialURL = nil;

if (self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey]) { initialURL = self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey];

}else if (self.bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]){ // keep in mind I’m extracting a dict here as my notification payload is a dictionary but it could be modified to extract any specific thing your payload sends NSDictionary *dict = self.bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; NSString *string_url = [dict valueForKey:@“url”]; initialURL = [NSURL URLWithString:string_url]; } else { NSDictionary *userActivityDictionary = self.bridge.launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey]; if ([userActivityDictionary[UIApplicationLaunchOptionsUserActivityTypeKey] isEqual:NSUserActivityTypeBrowsingWeb]) { initialURL = ((NSUserActivity *)userActivityDictionary[@“UIApplicationLaunchOptionsUserActivityKey”]).webpageURL; } } resolve(RCTNullIfNil(initialURL.absoluteString)); }

[“url”]: The url should be determined according to the key of the deeplink of the notification payload.

good luck!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Native deeplinking if app is closed doesn't work ( React ...
I have a problem regarding Deep Linking. If the app is closed(killed) and it is opened via a deep link it will take...
Read more >
Deep link from notification click not calling ... - Airship Support
Step 1 : Kill the application with right swipe. Step 2 : Send push from UA console for "sports" deep link. It will...
Read more >
How To Handle Deep Linking in a React Native App
In this tutorial, let's learn how to handle deep linking in a React Native app by creating an example app. We will create...
Read more >
Rich push notifications | Customer.io Docs
For now, our rich push feature only supports images and deep links. ... the handler is not set or returns null , the...
Read more >
iOS | Localytics Documentation - Upland Software
In order to run the Localytics SDK, you must initialize the SDK using your Localytics app key. You can find your app key...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found