Linking.getInitialURL() for android
See original GitHub issueHi,
On Android Linking.getInitialURL()
has a problem and not return anything.
More precisely, none of the following logs are executed.
Linking.getInitialURL().then((url) => {
console.log('Initial url is: ' + url);
}).catch(err => console.error('An error occurred', err));
but when i change https://github.com/facebook/react-native/blob/master/Libraries/Linking/Linking.js#L86-L92 to:
getInitialURL(): Promise<?string> {
return NativeLinking.getInitialURL();
}
the problem was fixed.
React Native version:
System:
OS: Linux 4.18 Ubuntu 18.04.2 LTS (Bionic Beaver)
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Memory: 582.26 MB / 15.50 GB
Shell: 4.4.20 - /bin/bash
Binaries:
Node: 10.16.0 - /usr/bin/node
Yarn: 1.17.3 - /usr/bin/yarn
npm: 6.9.0 - /usr/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
Android SDK:
API Levels: 28
Build Tools: 28.0.3, 29.0.0, 29.0.1
System Images: android-28 | Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom
Android NDK: 20.0.5594570
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.60.3 => 0.60.3
npmGlobalPackages:
react-native-cli: 2.0.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:71
- Comments:73 (6 by maintainers)
Top Results From Across the Web
Linking - React Native
Android calls it Deep Links (Universal Links - iOS). ... getInitialURL() - it returns a Promise that resolves to the URL, if there...
Read more >React-native linking getinitialurl() works even when I don't call ...
When I tap the link for first in-browser my app run but incoming URL don't clear after that and linking.GetInitialUrl() always run with...
Read more >Linking · React Native
getInitialURL().then((url) => { if (url) { console.log('Initial url is: ' + ... for deep linking on Android, refer to Enabling Deep Links for...
Read more >Linking - Expo Documentation
Android Device, Android Emulator, iOS Device, iOS Simulator, Web ... Linking.getInitialURL(). Get the URL that was used to launch the app if it...
Read more >Deep Linking Your React Native App | by Nader Dabit - Medium
Now, let's go into index.ios.js / index.android.js and import the router will ... getInitialURL().then(url => { this.navigate(url); }); } else { Linking.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well I’d argue that is almost completely broken then. Deeplinking is usually used when the app is not open.
I think there are probably 2 different issues/bugs here:
I think it probably makes sense to separate these 2 issues or at least declare which of the 2 people are seeing. For me, I am seeing number 2 above.
I did some testing around this and have come to similar conclusions to @Stephen2:
react-native init
and making some changes toApp.js
andAndroidManifest.xml
(to register intent to view certain URLs). I have pushed this sample app at https://github.com/stellaai/rndeeplinkSince the bug seems timing dependent and having put tracing debug statements throughout the native code, my hunch is that this relates to whether or not the React bridge is ready when the native code wants to set the initial URL by sending a message to the JS app via EventEmitter (if my reading of the code is correct and this is how it is set).
A workaround/hack (if using vanilla React Native or willing to eject from Expo managed workflow) might be to override the
getLaunchOptions
method in your ownReactActivityDelegate
subclass to explicitly get the URI from the Intent and pass it through as a prop to the root React component rather than relying on Linking.getInitialUrl(). See https://medium.com/@anutoshdatta/pass-initial-properties-to-react-native-from-java-or-objective-c-code-12880ba6198e for some details on this.I have put a video of these inconsistent results up here: https://github.com/stellaai/rndeeplink/blob/master/deeplinkbug.mp4 – note that pressing the the back button on Android destroys the activity, so this is showing a cold start every time.
Have also logged a bug in Expo prior to determining that this was a bug with RN upstream with some more logs, etc.: https://github.com/expo/expo/issues/8408