HMS-Core/hms-cordova-plugin

event onRemoteMessageReceived not fire

VChuharev opened this issue · 9 comments

the event in Remote Message Received is not triggered at any state of the application.

plugin version 6.9.0-300
platform android 11.0.0

there is an event in Logcat:
javascript:hmsEventHandler('REMOTE_DATA_MESSAGE_RECEIVED', {"msg":{"collapseKey":"-1","data":"{'type':'intercom'}","dataOfMap":"{type=intercom}","messageId":"ABAAstMf5WR4QPhkeGgIAKY88UQ6eTcAAAA","originalUrgency":"1","urgency":"2","ttl":"10000","sentTime":"1685602552745","from":"99536292102848687","token":"IQAAAACy0x_lAADrYnZdzQRMjFn1DM_8hD4TcEqIsNgOiexmZRipoQER08RKZqhimHkYaYjPPJx1_vjhfqIhL4dOy83TLpqzVd1E1pnr_421WahJNg","receiptMode":"0","sendMode":"0","contents":"0","analyticInfo":"{\"biTag\":\"the_sample_bi_tag_for_receipt_service\"}","analyticInfoMap":"{biTag=the_sample_bi_tag_for_receipt_service}","titleLocalizationArgs":"[]","bodyLocalizationArgs":"[]","ImageUrl":"null","Link":"null","NotifyId":"0","When":"null","LightSettings":"[]","BadgeNumber":"null","Importance":"0","vibrateConfig":"[]","visibility":"null","isAutoCancel":"true","isLocalOnly":"true","isDefaultLight":"true","isDefaultSound":"true","isDefaultVibrate":"true"}})

Hi @VChuharev,

If an uplink message is successfully sent by your app to your app server and the server responds to the message, a receipt will be sent to your app through the onRemoteMessageReceived() listener.

Have you enabled uplink message receiving through HTTPS in AppGallery Connect? This document may help you.

Hi @VChuharev,

If an uplink message is successfully sent by your app to your app server and the server responds to the message, a receipt will be sent to your app through the onRemoteMessageReceived() listener.

Have you enabled uplink message receiving through HTTPS in AppGallery Connect? This document may help you.

Thk. But I need to get data in the application from a message sent from the server, and not vice versa.

Cubaza commented

Hi,
I have same issue. @VChuharev have You maybe solve it? It's not working with data notification and even from example code downloaded from huawei :/

Init new function

function hmsEventHandler(data, data2) {
  if(data2) {
    console.log(data2.msg;) 
  }
}

when the date push arrives, the application generates a call to this function, then what needs to be done.

Cubaza commented

@VChuharev thank You very much. This was an issue and now everything is working fine. Thank You very much.

@Cubaza hi, may I know how did you fix it?

Cubaza commented

@iand2x2 I've created new global function with body posted by VChuharev in this message:
#130 (comment)
So in my code it looks like this:

window.hmsEventHandler = function(eventName, payload) {
            if(eventName === 'REMOTE_DATA_MESSAGE_RECEIVED' && payload && payload['msg']) {
                HmsLocalNotification.localNotification({
                    [HmsLocalNotification.Attr.title]: payload['msg'].title,
                    [HmsLocalNotification.Attr.message]: new HmsPush.CordovaRemoteMessage(
                        payload['msg'].text
                    ).getDataOfMap(),
                });
            }
        }

That code make that when DATA push notification will be passed to application it will fire event and show notification. I know that there are more events which this code could broke, but for my purpose (showing notification on application) it is working.

@ozkulbeng hi, can you pls describe your changes here: cd174a8#diff-071540fd2096627b7119d04b04c24066fd2196aee261a0c2f34dbb9475e51bd4R50

if (window.hmsEventHandlers.hasOwnProperty(eventName)) { you changed to if (Object.prototype.hasOwnProperty(eventName)) {

what is mean here Object.prototype.hasOwnProperty ?
Looks like it is a critical bug and we can not receive any events because here we will have every time false.

// call
window.hmsEventHandler('NOTIFICATION_OPENED_EVENT', {});
//
// if (Object.prototype.hasOwnProperty(eventName)) {
//            window.hmsEventHandlers[eventName].forEach((handler) => {
//                handler(data);
//            });
 //       }

 // eventName -> NOTIFICATION_OPENED_EVENT
 // Object - ?
 // Object.prototype.hasOwnProperty(eventName) - false, 


fixed 2 days ago 758a6e7