I have successfully implemented a universal link that opens up a specific page in my app (if the app is turned off). The problem is that if the app is running in the background, the eventListener is not being called. Here is the code:
import {Linking} from 'react-native';
export default class App extends React.Component {
async componentDidMount(){
Linking.addEventListener('url', this._handleOpenURL);
let url = await Linking.getInitialURL();
if (url) {
console.log('MOUNT GET INIT URL','initial url ' + url);
}
}
_handleOpenURL = (event) => {
console.log("in _handleOpenURL", event.url)
}
}
MOUNT GET INIT URL is successfully logged to the console. in _handleOpenURL is never logged. It seems other people on the internet have had this problem but no one has answered it. Does anyone know what to do?
Add this just before the last @end in appdelegate.m:
// iOS 9.x or newer
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With