HMS-Core / hms-cordova-plugin

This repo contains all of Cordova HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
88 stars 40 forks source link

event onRemoteMessageReceived not fire #130

Closed VChuharev closed 4 months ago

VChuharev commented 11 months ago

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"}})

ilsafarber commented 11 months ago

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.

VChuharev commented 11 months ago

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 11 months ago

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 :/

VChuharev commented 11 months ago

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 10 months ago

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

iand2x2 commented 10 months ago

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

Cubaza commented 10 months ago

@iand2x2 I've created new global function with body posted by VChuharev in this message: https://github.com/HMS-Core/hms-cordova-plugin/issues/130#issuecomment-1601307985 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.

expcapitaldev commented 9 months ago

@ozkulbeng hi, can you pls describe your changes here: https://github.com/HMS-Core/hms-cordova-plugin/commit/cd174a8c5e2fe7dfdc6fc58147f6cceddfb5c733#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, 
expcapitaldev commented 7 months ago

fixed 2 days ago https://github.com/HMS-Core/hms-cordova-plugin/commit/758a6e7623753e87f6a2b13867fe4ce585baee82