React-native-onesignal: Deep link is not firing up when app is in killed state

Created on 22 Apr 2019  路  12Comments  路  Source: OneSignal/react-native-onesignal

Description:
Deep link is working when app is launched first but it is not working when the app is in killed state. I'd tried few solutions but still not seeing it working for both iOS and android

Environment

Steps to Reproduce Issue:

Do not start app
Open app by clicking any deep link url
Event fired
App is not directly goes to URL page
App stayed in Home Page

Help Wanted

Most helpful comment

I have the same issue with the react-navigation deep link. I turn on the debugger and the deep link not work when the app killed. simply turn off debug and solve for me. Hope can help somebody!. :)

All 12 comments

@izakarim please post the actual code you鈥檙e using for the notification opened handler.

@izakarim please post the actual code you鈥檙e using for the notification opened handler.

componentWillMount() {
AppState.addEventListener('change', (status) => this.handleAppStateChange(status));
Linking.addEventListener('url', this.handleOpenURL);
this._checkDeepLink();
}

componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', () => this.handleBackButtonClick());
this.mapDeepLinkRoutes();
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', () => this.handleBackButtonClick());
AppState.removeEventListener('change', this.handleAppStateChange);
Linking.removeEventListener('url', this.handleOpenURL);
NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectionChange);
}

handleConnectionChange=(isConnected)=> {
this.setState({status: isConnected});
console.log(is connected: ${this.state.status});

if (!this.state.status) {
  this.props.dispatch(routeActions.resetCheckout('NoNetworkPage'));
  this.props.dispatch(alertActions.pageIsClosed());
}

};

handleAppStateChange(nextAppState) {

const isProcessing = this.props.placeOrder && this.props.placeOrder.isProcessing || false;
const isSuccess = this.state.incomingURL.includes('appname://order/success');
console.log('this.state.incomingURL', this.state.incomingURL);
console.log('this.props.placeOrder', this.props.placeOrder);

if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
  console.log('App has come to the foreground!');
  this.props.dispatch(userActions.isNotGuest());
  if (isProcessing === true && !isSuccess) {
    console.log('Im in the loop', this.state.incomingURL);

    this.props.dispatch(routeActions.resetCheckout('CheckoutFailPage'));
  }

  this.props.dispatch(placeOrderActions.placeOrderStop());
  if (this.state.incomingURL) {
    this.setState({incomingURL: ''});
  }
}
this.setState({appState: nextAppState});

}

handleOpenURL(event) {
const scheme = 'appname';

if (event.url && event.url.includes(scheme + '://')) {
  this.setState({incomingURL: event.url});
  crossroads.parse(event.url.slice(scheme.length + 3));
}

}

Hello,
I'm not sure what is going wrong here. However, we always main recommend deeplinking using additional data as we have previously seen issues with people taking your approach. You could then use a react navigation library to open the screen you wish.

@izakarim Both your original post and the code snippet you posted don't even mention either notifications or onesignal. This is the repo for rn-onesignal, a notification handling library. You should probably post your question in the general react-native stack overflow

Closing due to no response from OP

So there's no way of deep linking in React Native?
I need to redirect from my logged in home page to a details page, read the android and ios native approach but not sure how and where to implement the native code among all the react native code i already got.

@FelipeGatti Have you looked into using a navigation or routing library for React Native in combination with the onOpened callback?

@rgomezp I've managed to achieve this by setting a prop in my root component (screenProps from react-navigation) in the onOpened callback but i'm not sure if it's the best way since my entire app gets reloaded before it gets routed to the push notification related scene wich, in this case, is not a big deal but could be in a bigger and more complex application.

I see. Well I'm very glad you figured it out!

I have the same issue with the react-navigation deep link. I turn on the debugger and the deep link not work when the app killed. simply turn off debug and solve for me. Hope can help somebody!. :)

I have the same issue with the react-navigation deep link. I turn on the debugger and the deep link not work when the app killed. simply turn off debug and solve for me. Hope can help somebody!. :)

did you solve this issue , if you done , please help me . I also get this issue

I have the same issue with the react-navigation deep link. I turn on the debugger and the deep link not work when the app killed. simply turn off debug and solve for me. Hope can help somebody!. :)

did you solve this issue , if you done , please help me . I also get this issue

@toanpv-2417 just turn off debugger. it'll work. please try this. it has done for me.

Was this page helpful?
0 / 5 - 0 ratings