-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
React native deep linking not working when app is in background state #24624
Comments
Can you run If you believe this information is irrelevant to the reported issue, you may write `[skip envinfo]` alongside an explanation in your Environment: section.
|
It looks like you are using an older version of React Native. Please update to the latest release, v0.59 and verify if the issue still exists. The "Resolution: Old Version" label will be removed automatically once you edit your original post with the results of running `react-native info` on a project using the latest release.
|
are you added
in AndroidManifest.xml ? |
Yes, I have already added this in 'my_project/android/app/src/main/AndroidManifest.xml. Example of code:
|
Any updates on this? |
@DalbirKaur were you able to solve for this? |
@platonish, I am not able to get any lead yet. |
I'm having the same issue in android I'm not able to get the URL to make any action |
@DalbirKaur can you attach AndroidManifest.xml file ? |
@maleking, I have pasted the content of AndroidManifest.xml file of my project. Because I was unable to attach the .xml file. |
For me, the issue was that although the app would come to the foreground on clicking on the app link (say from an SMS), the callback passed to So what I ended up doing is this: add an componentDidMount() {
// triggered when react native boots
this._checkInitialUrl()
AppState.addEventListener('change', this._handleAppStateChange)
// never gets fired on Android, hence useless to me
// Linking.addEventListener('url', url => console.log('url received: ', url))
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange)
}
_handleAppStateChange = async (nextAppState) => {
if (
this.state.appState.match(/inactive|background/) &&
nextAppState === 'active'
) {
this._checkInitialUrl()
}
this.setState({ appState: nextAppState })
}
_checkInitialUrl = async () => {
const url = await this._getInitialUrl()
this._handleUrl(url)
}
_getInitialUrl = async () => {
const url = await Linking.getInitialURL()
return url
}
_handleUrl = (url) => {
// write your url handling logic here, such as navigation
console.log('received URL: ', url)
} |
Same issue here on 59.8. |
Does any one have a work around on this? I'm facing the same issue for Android devices. |
@tranthienhao I am also wondering this. Does anyone have any light to shed on this? Is this a bug, or does |
@apamphilon try the below code.
this is working if the app is in background state too. |
@DalbirKaur Thanks for the suggestion. I did try and do it this way but found that if the deep link has already been navigated to and then you switch screens and put the app back into the background and then relaunch, the event listener will fire again and navigate to that screen again. Any thoughts? |
for me, the issue with using appState as a workaround is that on iOS Linking.addEventListener('url') will get the latest url sent to the app - this is helpful if the app is used to share URLs. So each time a URL is sent to the app, it receives the correct one. Using appState and getInitialURL you only ever get the first url the app was launched with. Is there any update on getting Linking.addEventListener('url') working properly on Android? |
I am also facing same issue Linking.addEventListener('url') returns the initial url only, or Linking.getInitialURL() returns null. Linking.removeEventListener('url') doesnt work, how can we remove the existing url and get the latest url. |
Does anyone can solve keep getting the old url instead of latest url issue? |
Also facing this issue. The event listener fails to fire if the app is not already open. |
Same issue, seems like |
// Add Listener to catch a state
|
Is there an update on this issue ? Deep linking is an important feature, and this issue makes it pretty much unusable |
So, apparently, it works just fine if you turn off the debugger |
I give you my hook that works grate on Android and IOS.
|
This worked for me for both background and foreground const useDeepLink = (props) => {
}; export default useDeepLink; |
Hi @Kingsace Were you able to solve this issue by any chance? I am facing the same issue where Linking.getInitialUrl() gets a older url on some samsung devices. |
I suggest you to follow the rn-firebase guide to do it right. I do that and my hook ends as follow: const useDeepLink = (callback: (url: string) => void) => {
const handleDynamicLink = useCallback(
(link: any) => {
console.log({link});
if (link && link.url) {
callback(link.url);
}
},
[callback],
);
useEffect(() => {
dynamicLinks()
.getInitialLink()
.then(handleDynamicLink);
const unsubscribe = dynamicLinks().onLink(handleDynamicLink);
return () => unsubscribe();
}, [handleDynamicLink]);
}; |
Look again I post my end solution that work's greate. you need to follow
the guide trust in me when you do it right it works.
El mar, 20 abr 2021 a las 23:46, Siddhartha Baral ***@***.***>)
escribió:
… Does anyone can solve keep getting the old url instead of latest url issue?
Hi @Kingsace <https://github.com/Kingsace> Were you able to solve this
issue by any chance? I am facing the same issue where
Linking.getInitialUrl() gets a older url on some samsung devices.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#24624 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AH3B56KD4DTLQI44D54JGTTTJZDALANCNFSM4HIVMF6A>
.
|
This applies only to the existing instances of the activity. This is the text from the link that you've given: "If you wish to receive the intent in an existing instance of MainActivity,<...>". In other words the developer chooses whether he wants multiple instances of the app activity or only one. So it's not related to this issue. |
Can you please explain why this hook works? |
Hello Everyone! The deep linking is working as expected for me even the app is in
Please check if you have added below line in your
It must be added above Please check if you have added below code in your
It will work for app cold boot, but it will not work if your app is in
This should work irrespective of your AppState: This worked for me as expected! Give it a try. This is should definitely work. Thanks in advance! |
I get an error as "Cannot resolve method getReactInstanceManager". Can you please help me to fix this issue? |
For the ones that have this problem in iOS when the app is in the background (so not a cold start), my problem was that Firebase was overriding the continueUserActivity call with its own inside the GLUAppDelegateSwizzler.m. The way I fixed it was by adding this to the info.plist file:
|
We are experiencing this issue on |
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. |
Turning off the debugger worked for me. |
For anyone who is interested in the swizzler, its correct filename is |
Facing the same issue only on android 12, any updates? |
Facing the same issue on Android. |
Piggy backing on @RZulfikri suggestion for android I just had to add:
in the MainActivity.java And handle deep linking in the app's root component:
This worked for me!! |
=======>>>Method to catch Deep link when App opens <<<=======
},[]); =======>>>Method to catch Deep link when App is In Background <<<======= useEffect(() => {
}, []); |
This saved me! Thx |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
🐛 Bug Report
When the app is closed, I am able to get deep link url that is clicked by Linking.getInitialURL(). When the app is in the background state, then nothing is mounted. So, I am not able to get the url even by the Linking.addEventListener('url', method_name).
What is the way to achieve this?
To Reproduce
Expected Behavior
Code Example
componentDidMount() {
Linking.addEventListener('url', this._handleOpenURL);
},
componentWillUnmount() {
Linking.removeEventListener('url', this._handleOpenURL);
},
_handleOpenURL(event) {
console.log(event.url);
}
I have added this code in app.js
Environment
React Native Environment Info:
System:
OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
CPU: (4) x64 Intel(R) Core(TM) i3-6098P CPU @ 3.60GHz
Memory: 1.73 GB / 15.57 GB
Shell: 4.4.19 - /bin/bash
Binaries:
Node: 10.11.0 - /usr/bin/node
npm: 6.7.0 - /usr/bin/npm
npmPackages:
react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728
react-native: ^0.58.5 => 0.58.5
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1
react-native-rename: 2.4.0
react-native-slideshow: 1.0.1
The text was updated successfully, but these errors were encountered: