OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.56k stars 373 forks source link

setNotificationWillShowInForegroundHandler does not working in HMS environment #1188

Closed sktan810 closed 3 years ago

sktan810 commented 3 years ago

Description: I'm currently integrating OneSignal react-native plugin in both HMS and GMS environment, it seems like does not work in HMS environment in Huawei device without GMS. But it works in normal Android GMS device. I follow all the guidelines in OneSignal documentation as well as contacting support team in OneSignal, but seems like does not getting solution and fixes from both sides.

I able to get getDeviceState() returned values, but setNotificationWillShowInForegroundHandler() I can't get any values after test push messages from OneSignal server as well as using postman API.

Environment react-native-onesignal": "^4.0.5" gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99] com.huawei.agconnect:agcp:1.4.2.301 com.huawei.agconnect:agconnect-core:1.4.2.301 com.huawei.hms:push:5.0.2.300

Steps to Reproduce Issue:

  1. open the app and stay in foreground
  2. send a push notification to the app via Postman and also OneSignal dashboard
  3. GetDeviceState is get called, with all required token, ids and states.
  4. My receiver handler is not called
jkasten2 commented 3 years ago

@sktan810 This is a current limitation with the OneSignal SDK and the Huawei integration with the "message" type which is default. It is possible to change this to the "data" type to match how OneSignal sends FCM message by setting "huawei_msg_type": "data". If you have a message body a "data" type message will still be displayed. https://documentation.onesignal.com/reference/create-notification#attachments

However due note that on Huawei devices force kill apps more aggressively so "data" message may not be able to start your app for the notification to be displayed.

sktan810 commented 3 years ago

@sktan810 This is a current limitation with the OneSignal SDK and the Huawei integration with the "message" type which is default. It is possible to change this to the "data" type to match how OneSignal sends FCM message by setting "huawei_msg_type": "data". If you have a message body a "data" type message will still be displayed. https://documentation.onesignal.com/reference/create-notification#attachments

However due note that on Huawei devices they force kill apps more aggressively so "data" message may not be able to start your app for the notification to be displayed.

@jkasten2 Alright, it works after adding "huawei_msg_type": "data" in backend API and tested with Postman.

Plus, HMS core need to be updated to latest version and Allow the permission of Location and Notifications, in order to retrieve the values in setNotificationWillShowInForegroundHandler.

npulidom commented 3 years ago

Worked as @jkasten2 described. Last versions of HMS kit can be found here: https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/hmssdk-kit-0000001050042513-V5