Description:
I'm using OneSignal React Native SDK and successfully integrated OneSignal with both Android and IOS and push notifications are working perfect as well.
But there is an issue with displaying the notifications. I wanted to use the notification Shade, which is [2] option for the inFocusDisplaying method. IOS started to working after adding the optional parameter
kOSSettingsKeyInFocusDisplayOption to the init function but couldn't get shade notifications to work on Android. Options [0] and [1] are working by the way.
Already gone through the previously posted issues but only found inFocusDisplaying issues related to IOS.
Notifications are working only need notification Shade to work on Android. inFocusDisplaying(2)
Environment
Steps to Reproduce Issue:
Anything else:
This is the function where I'm initializing the SDK.
subscribe = () => {
this.mode = "subscribe";
os.init(contants.ONESIGNAL_APP_ID, {kOSSettingsKeyInFocusDisplayOption: 2});
os.setSubscription(true);
os.inFocusDisplaying(2);
this.addEventListeners();
os.configure();
}
Same problem for me. iOS works but android not work.
Happens for me on iOS too. This is pretty important imo.
Any update on this?
I've tested this and I am not able to reproduce. Looking at the OP's code, it seems like the issue would likely be that his subscribe() function isn't getting called?
Please make sure to call OneSignal.init() immediately when the app launches, don't wait until some later point. If you don't want the user to receive push notifications and don't want them to get prompted for permission, that's fine, but don't delay initialization of the SDK.
Also, please call OneSignal.inFocusDisplaying() before you call OneSignal.init().
@Nightsd01
Sorry, didn't see my github notification. Still doesn't work for me, no luck receiving notifications when the app is open, although out of app notifications are received fine.
it seems like the issue would likely be that his subscribe() function isn't getting called?
I tried calling OneSignal.subscribe(), but it's not a function.
Please make sure to call OneSignal.init() immediately when the app launches, don't wait until some later point
I'm calling it in componentDidMount
please call OneSignal.inFocusDisplaying() before you call OneSignal.init().
tried that, still no luck.
I'm initialising OneSignal like this (in src/Main.js component):
componentDidMount() {
console.disableYellowBox = true
OneSignal.inFocusDisplaying(2)
OneSignal.setSubscription(true)
// OneSignal.subscribe(true)
OneSignal.init(oneSignalAppId, {
kOSSettingsKeyAutoPrompt: false,
kOSSettingsKeyInFocusDisplayOption: 2,
})
OneSignal.configure()
OneSignal.enableSound(true);
OneSignal.enableVibrate(true);
OneSignal.addEventListener('received', this.onReceived);
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('ids', this.onIds);
this.authenticate()
}
That's my index.js
import React, { PureComponent } from 'react'
import { AppRegistry } from 'react-native'
import { Provider as StoreProvider } from 'react-redux'
import App from 'src/Main'
import configureStore from 'src/store/configureStore'
const store = configureStore()
class app extends PureComponent {
render() {
return (
<StoreProvider store={store}>
<App />
</StoreProvider>
)
}
}
AppRegistry.registerComponent('app', () => app)
Anything wrong you can pick out?
Any update on this?
Hi @noway,
Sorry for the delay. Make sure to initialize OneSignal before you do anything else. Check out the usage in our documentation.
Closing for now. Feel free to reply here and tag us and we can re-opoen the issue
I'll try to test it next week.
Same problem for me on iOS and Android.
OneSignal.init(ONESIGNAL_APP_ID, {
kOSSettingsKeyAutoPrompt: false,
kOSSettingsKeyInFocusDisplayOption: 2,
});
OneSignal.inFocusDisplaying(2);
OneSignal.addEventListener('received', this.onReceived);
if (__DEV__) {
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('ids', this.onIds);
}
if (this.props.player.id) {
OneSignal.setExternalUserId(this.props.player.id);
}
OneSignal.configure();
I haven't tested rejigging initialization code, i still experience this too.
I'm with the same problem on Android. When I try out inFocusDisplaying() with the values 0 and 1, it works fine. The 0 does nothing with incoming notification, and the 1 value shows inapp Alert with the notification title and body correctly, just like is documented.
But the 2 value does nothing, and it's working exactly like the 0.
In fact, doing debugs, I could realize that the incoming notification has the key displayType with value 0, even when I'm using inFocusDisplaying(2). Just don't get it what is happening here...
Note: The Notification Shade never appears, on back or foreground, and even with the app in dead state. It only triggers the notification sound and it shows the app icon on Android StatusBar.
Here's my code:
export function initOneSignal() {
OneSignal.init(APP_ID);
OneSignal.inFocusDisplaying(2);
OneSignal.setSubscription(true);
OneSignal.configure();
return;
}
My enviroment:
Android:
Thanks for your patience while we investigate
@BrunoPes can you try this: https://github.com/geektimecoil/react-native-onesignal/issues/164#issuecomment-275311345 ?
I can confirm that this is still not working in my production app. @rgomezp any news on that ?
I'm using a Galaxy s7
Howdy @EnanlyPay ,
I just tested on a Galaxy S8 and the setting still works as expected. Have you taken a look at the logcat for the device when you reproduce the issue?
Closing due to no response
the issue doesn't happen for me anymore on
"react-native-onesignal": "^3.3.2",
"react-native": "^0.60.5",
for ios. not sure about android
@noway , in either case that's an old version of the package. consider upgrading
will do
@Nightsd01 why is it bad to init OneSignal sometime later in the app and not immediately?