iOS Linking getInitialURL() always null
See original GitHub issue🐛 Bug Report
I can’t get the deep link url that was called when my app is started on iOS.
Tried with Linking.getInitialUrl()
promise and by listener addEventListener('url'...)
None of these methods return the initial url.
When the app is in background, the listener addEventListener('url', ...)
is working well, and we can get the url. But when the app is launched via a deeplink, we don’t have it.
I tried on React Native 0.53.3
it’s working via getInitialUrl()
and listener.
I tried on React Native 0.59.4
not working.
To Reproduce
1. Add URL type to info.plist.
2. Add this to your AppDelegate.m
:
#import <React/RCTLinkingManager.h>
...
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
3. and just to test, update your App.js
to look like this :
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Linking
} from 'react-native';
type Props = {};
export default class App extends Component<Props> {
componentDidMount() {
Linking.getInitialURL().then((url) => { console.log('1', url) })
Linking.addEventListener('url', this.handleOpenURL);
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleOpenURL);
}
handleOpenURL(event) {
console.log('2', event.url);
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</View>
);
}
}
Expected Behavior
I expect to get the initial URL called via deeplink via getInitialUrl
or listener handler.
Environment
info
React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Memory: 205.05 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 11.11.0 - /usr/local/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 19, 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 24.0.1, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.3
System Images: android-19 | Google APIs ARM EABI v7a, android-19 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom, android-25 | Google Play Intel x86 Atom, android-27 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5264788
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.4 => 0.59.4
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-git-upgrade: 0.2.7
Thanks for your time 😉
Issue Analytics
- State:
- Created 4 years ago
- Reactions:107
- Comments:67 (4 by maintainers)
Top Results From Across the Web
Why is Linking.getInitialURL always returning null?
If the app is already running in background, getInitialURL() returns the link that launched it, otherwise I get null. I expect to get...
Read more >iOS : Why is Linking.getInitialURL always returning null?
iOS : Why is Linking. getInitialURL always returning null ? [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] iOS : Why is ...
Read more >Why is Linking.getInitialURL always returning null?-React Native
Coding example for the question Why is Linking.getInitialURL always returning null?-React Native.
Read more >Developers - [ ] Linking.getInitialURL returns null on iOS with ...
Linking.getInitialURL returns null on iOS with DynamicLinks setup.
Read more >Linking · React Native
getInitialURL().then((url) => { if (url) { console.log('Initial url is: ' + ... NOTE: On iOS, you'll need to link RCTLinking to your project...
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
Hi, In my project with react-navigation 3.9.1 and react-native 0.59.5 deep linking don’t work on ios simulator when “Debug JS remotely” is enabled, but work well when the debug is disabled. Could you try getInitialURL() without debug mode ?
On Android getInitialURL() works as expected, the issue is on iOS, url always comes up null. react-native 0.59.x