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
89 stars 42 forks source link

HMS Push Notification with type "data" does not come to the application when app in killed state (Ionic-Capacitor) #108

Closed mkvashennikov closed 1 year ago

mkvashennikov commented 1 year ago

Description Hello, help me please with my issue.😇 HMS Push Notification with type "data" does not come to the application when app in killed state. I copied the code from your example for my project, and set this.hmsPush.setBackgroundFile('public/assets/background.js'), but background file is not working for create local notification. Maybe I missed something?

Expected behavior When a notification with the "data" type arrives, this code should work in a file background.js:

onBackgroundRemoteMessageReceived((remoteMessage)=>{
  const jsonData = JSON.parse(remoteMessage.data);
  const headlessNotification = {
              "title": "[Headless] " + jsonData.title,
              "message": jsonData.message.replace("{{name}}","YourName")
          };
  const notification = JSON.stringify(headlessNotification);
  HmsLocalNotification.backgroundLocalNotification(notification);
});

Current behavior Local notification is not created in app killed state.

Environment

Xuejiao-Shi commented 1 year ago

Please see if this guide solves your issue: https://forums.developer.huawei.com/forumPortal/en/topic/0201622509719960128

mkvashennikov commented 1 year ago

Please see if this guide solves your issue: https://forums.developer.huawei.com/forumPortal/en/topic/0201622509719960128

Unfortunately, this method does not work😥

mkvashennikov commented 1 year ago

I found a solution for Ionic/Capacitor. It was necessary to upload the file via this.hmsPush.setBackgroundFile('public/assets/background.js'); And create a file in the directory www/assets/background.js. Thanks for help! 😇