Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
darbaoui opened this issue Apr 22, 2020 · 15 comments
Closed

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

darbaoui opened this issue Apr 22, 2020 · 15 comments
Labels
API: Linking Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. Needs: Issue Template This issue does not make use of the Issue Template, and may be missing necessary information. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@darbaoui
Copy link

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
@darbaoui darbaoui changed the title Deep linking return null via notification when i kill the app Deep linking return null via push notification when i kill the app Apr 22, 2020
@react-native-bot react-native-bot added API: Linking Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. and removed Needs: Triage 🔍 labels Apr 22, 2020
@github-actions
Copy link

⚠️ Missing Environment Information
ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

@hramos hramos added Needs: Issue Template This issue does not make use of the Issue Template, and may be missing necessary information. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available labels Apr 22, 2020
@github-actions
Copy link

⚠️ Using Old Version
ℹ️ It looks like you are using an older version of React Native. Please upgrade to the latest version, and verify if the issue persists. If it does not, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the current release.

@github-actions
Copy link

⚠️ Missing Reproducible Example
ℹ️ It looks like your issue is missing a reproducible example. Please provide a Snack or a repository that demonstrates the issue you are reporting in a minimal, complete, and reproducible manner.

@github-actions
Copy link

⚠️ Missing Required Fields
ℹ️ It looks like your issue may be missing some necessary information. GitHub provides an example template whenever a new issue is created. Could you go back and make sure to fill out the template? You may edit this issue, or close it and open a new one.

@stale
Copy link

stale bot commented Jul 25, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 25, 2020
@Aure77
Copy link

Aure77 commented Jul 29, 2020

I facing exact same issue.

RCTLinkingManager is call with url in native side. But Linking.getInitialURL() is resolved as null in RN.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 29, 2020
@Aure77
Copy link

Aure77 commented Jul 29, 2020

Similar to #11191

@cx5168
Copy link

cx5168 commented Aug 14, 2020

same issue.

Deeplink can be obtained by calling Linking from the hyperlink of the browser, but deeplink cannot be obtained by calling Linking after clicking push notification.

any way for it?

@cx5168
Copy link

cx5168 commented Aug 14, 2020

follow:
#5047

solved it!

@Aure77
Copy link

Aure77 commented Aug 14, 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).

@cx5168
Copy link

cx5168 commented 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!

@stale
Copy link

stale bot commented Dec 25, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 25, 2020
@emawby
Copy link

emawby commented 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.

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label May 24, 2021
@github-actions
Copy link

github-actions bot commented Mar 3, 2023

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 3, 2023
@github-actions
Copy link

This issue was closed because the author hasn't provided the requested feedback after 7 days.

@facebook facebook locked as resolved and limited conversation to collaborators Mar 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API: Linking Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. Needs: Issue Template This issue does not make use of the Issue Template, and may be missing necessary information. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

6 participants