Skip to content
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

onOpened event not triggered when app runs in background. #581

Closed
DNoreth opened this issue Jul 8, 2018 · 6 comments
Closed

onOpened event not triggered when app runs in background. #581

DNoreth opened this issue Jul 8, 2018 · 6 comments

Comments

@DNoreth
Copy link

DNoreth commented Jul 8, 2018

Description:
Hi guys this is my first call for help. I have an issue getting the onOpened event to fire when a notification is clicked on when the app is running in the background. It works perfectly from a cold start meaning when the app is completely closed and opened by pressing on the notification. onReceived, Init and everything else works fine. Followed the setup docs as is. Ive been reading everywhere and looked at the example project.

Environment
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-onesignal": "^3.2.5"

Added using Yarn

compileSdkVersion 23
buildToolsVersion "27.0.3"

Running on Android device

Steps to Reproduce Issue:

  1. Installed OneSignal using Yarn
  2. Successfully registered device on OneSignal Platform.
  3. Successfully sent tags.
  4. Successfully received push notifications using Onsignal platform and postman.
  5. onReceived event triggers every time with payload data. (Success)
  6. When push notification is received and pressed while the app is completely closed , app will launch and alert inside of the onOpened method will fire. (Success)
  7. When app is running in the background and notification is received and pressed the app will come into focus but the Alert in the onOpened method wont fire. (Failure)

`
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
AppState,
Text,
Alert,
View
} from 'react-native';
import { Root } from "native-base";
import { Router, Scene, Actions } from 'react-native-router-flux';
import OneSignal from 'react-native-onesignal';

import stores from './app/libs/mrDataLib';
import { observer, Provider, inject } from 'mobx-react/native'
import onBoarding from './app/pages/onBoarding/mrOnBoarding';

export default class App extends Component {
constructor(props) {
super(props);
this.state = {
};
}

componentWillMount() {
OneSignal.init("xxxxxxxx-xxxxxxx-xxxxxxxx-xxxxxxx");
OneSignal.configure();
OneSignal.inFocusDisplaying(2);
}

componentDidMount() {
this.onOpened = this.onOpened.bind(this); // Taken from onesignal example
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('received', this.onReceived);

}

componentWillUnmount() {
OneSignal.removeEventListener('received', this.onReceived);
OneSignal.removeEventListener('opened', this.onOpened);
}

onOpened(openResult) {
// This is where my problem lies
// Fires when app is not running and opened from notification clicked.
// Does not fire when app is running in the background or minimised.
Alert.alert('Test');
};

onReceived(notification) {
Alert.alert('Test');
}

render() {
return (
<Root>
<Provider store={stores}>
<Router wrapBy={observer}>
<Scene key="root">
<Scene hideNavBar={true} key="onBoarding" back={false} component={onBoarding} title="onBoarding" initial={true} />
</Scene>
</Router>
</Provider>
</Root>
);
}

Anything else:

I have looked online but with no luck, please can you help me.

@slorber
Copy link
Contributor

slorber commented Aug 3, 2018

Have you seen this issue regarding RN app restarts? #583

@Nightsd01
Copy link
Contributor

This issue should now be fixed in version 3.2.6

@d-olivas
Copy link

Hello,

I'm having the same problem. When the app is in the background and I open the notification it takes me to the app but it doesn't trigger the events, and when the app is opened or not opened at all it works fine.

Here are the versions I'm woking with:
"react": "16.8.6"
"react-native": "0.59.4"
"react-native-onesignal": "3.2.12"

I'm also running it on an android device, android version 9. I haven't been able to test it on an iPhone yet.

@riadhriadh
Copy link

add OneSignal.inFocusDisplaying(2);

@tvhimanshu
Copy link

I am using one signal version "react-native-onesignal": "^3.5.0"
still facing the same issue: onOpened event not triggered when app runs in background

@rukmanary
Copy link

Still not working, any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants