为什么HMS推动套件onbackgroundRemoteMoteMoteMessageEceived()不在background.js文件中触发
My Ionic capacitor is set as per these
this.hmsPush.setBackgroundFile("public/assets/background.js")
background.js
var data = {
"key":"value"
};
onGetItemResponse((result)=>{
console.log(JSON.stringify(result));
});
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);
});
HmsPush.setItem("test",JSON.stringify(data));
HmsPush.getItem("test");
HmsPush.removeItem("test");
更新1 这是我尝试发送和数据消息和应用程序已经杀死的日志。
这条线很可疑
04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}
04-25 10:20:01.776 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]enter cancelAlarm(Action=com.huawei.android.push.intent.RESPONSE_FAIL
04-25 10:20:01.778 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]process cmdid to receive from pushSrv:44, subCmdId:FF
04-25 10:20:01.783 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]dispatchIntent over
04-25 10:20:01.785 I/PushLog110105309( 5138): [ReceiverDispatcher-209]process push message cmdid from pushSrv:44, subCmdId:FF
04-25 10:20:01.796 I/PushLog110105309( 5138): [ReceiverDispatcher-209]msgType:3 [0:PassBy msg, 1:System notification, 2:normal notification, 3:HCM PassBy msg],userId:0
04-25 10:20:01.799 I/PushLog110105309( 5138): [ReceiverDispatcher-209] closeTokenCheck: false
04-25 10:20:01.802 I/PushLog110105309( 5138): [ReceiverDispatcher-209]app declare HmsMessageService num is: 1
04-25 10:20:01.802 I/PushLog110105309( 5138): [ReceiverDispatcher-209]judge process is running start
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]no running process.
04-25 10:20:01.805 W/PushLog110105309( 5138): [ReceiverDispatcher-209]process com.**** not exist and control 0
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]tempDozeWhileListTime = 10000
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]add com.**** to doze temp white list
04-25 10:20:01.807 I/PushLog110105309( 5138): [ReceiverDispatcher-209]do not need to apply net.
04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}
04-25 10:20:01.809 W/PushLog110105309( 5138): [ReceiverDispatcher-209]start remote message service failed
04-25 10:20:01.813 I/PushLog110105309( 5138): [ReceiverDispatcher-209]message 0A3680A0490F8108 is cached success: true
04-25 10:20:01.814 I/PushLog110105309( 5138): [ReceiverDispatcher-209]send passby message by start service for: com.****,msgID:0A3680A0490F8108
04-25 10:20:01.814 I/PushLog110105309( 5138): [ReceiverDispatcher-209]process cmdid to send to pushSrv:45, subCmdId:FF
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]send msg to remote srv success
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]handleMessageResponse the response msg is :45,msgId:0A3680A0490F8108,displayPkgName:com.****,flag:1B
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]enter AlarmTools:setInexactAlarm(intent:Intent { act=com.huawei.action.push.intent.CHECK_CHANNEL_CYCLE pkg=android } interval:1200000ms
My Ionic capacitor is set as per these instructions. It is able to receive data messages just fine when the app is in the background or foreground. But the background.js script is not being called when the app is killed.
this.hmsPush.setBackgroundFile("public/assets/background.js")
background.js
var data = {
"key":"value"
};
onGetItemResponse((result)=>{
console.log(JSON.stringify(result));
});
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);
});
HmsPush.setItem("test",JSON.stringify(data));
HmsPush.getItem("test");
HmsPush.removeItem("test");
Update 1
Here is the log when I try to send and data message and the app is already killed.
This line is suspicious
04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}
04-25 10:20:01.776 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]enter cancelAlarm(Action=com.huawei.android.push.intent.RESPONSE_FAIL
04-25 10:20:01.778 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]process cmdid to receive from pushSrv:44, subCmdId:FF
04-25 10:20:01.783 I/PushLog110105309( 5138): [SocketRead_09:20:20-233]dispatchIntent over
04-25 10:20:01.785 I/PushLog110105309( 5138): [ReceiverDispatcher-209]process push message cmdid from pushSrv:44, subCmdId:FF
04-25 10:20:01.796 I/PushLog110105309( 5138): [ReceiverDispatcher-209]msgType:3 [0:PassBy msg, 1:System notification, 2:normal notification, 3:HCM PassBy msg],userId:0
04-25 10:20:01.799 I/PushLog110105309( 5138): [ReceiverDispatcher-209] closeTokenCheck: false
04-25 10:20:01.802 I/PushLog110105309( 5138): [ReceiverDispatcher-209]app declare HmsMessageService num is: 1
04-25 10:20:01.802 I/PushLog110105309( 5138): [ReceiverDispatcher-209]judge process is running start
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]no running process.
04-25 10:20:01.805 W/PushLog110105309( 5138): [ReceiverDispatcher-209]process com.**** not exist and control 0
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]tempDozeWhileListTime = 10000
04-25 10:20:01.805 I/PushLog110105309( 5138): [ReceiverDispatcher-209]add com.**** to doze temp white list
04-25 10:20:01.807 I/PushLog110105309( 5138): [ReceiverDispatcher-209]do not need to apply net.
04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}
04-25 10:20:01.809 W/PushLog110105309( 5138): [ReceiverDispatcher-209]start remote message service failed
04-25 10:20:01.813 I/PushLog110105309( 5138): [ReceiverDispatcher-209]message 0A3680A0490F8108 is cached success: true
04-25 10:20:01.814 I/PushLog110105309( 5138): [ReceiverDispatcher-209]send passby message by start service for: com.****,msgID:0A3680A0490F8108
04-25 10:20:01.814 I/PushLog110105309( 5138): [ReceiverDispatcher-209]process cmdid to send to pushSrv:45, subCmdId:FF
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]send msg to remote srv success
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]handleMessageResponse the response msg is :45,msgId:0A3680A0490F8108,displayPkgName:com.****,flag:1B
04-25 10:20:01.815 I/PushLog110105309( 5138): [ReceiverDispatcher-209]enter AlarmTools:setInexactAlarm(intent:Intent { act=com.huawei.action.push.intent.CHECK_CHANNEL_CYCLE pkg=android } interval:1200000ms
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在杀戮状态下,您可以在日志中找到此信息吗? “ ** onMessageReceived **”
您可以使用此命令来捕获日志:
adb logcat -c&& adb logcat -vtime> logcat1.txt
In killing state, can you find this information in log? " ** onMessageReceived ** "
You can use this command to catch log:
adb logcat -c && adb logcat -vtime > logcat1.txt
日志告诉根本原因。
04-25 10:20:01.809 W/ActivityManager(1461):IAWare或Trustsbase Sinfo ServiceInfo {8882F89 com.huawei.hms.hms.hms.hms.cordova.push.remote.remote.hmspushmesservice}
解决方案。启动时只需添加一个延迟,
请参考此URL以获取更多信息: https://blog.katastros.com/a?id=01750-e3e353a0-ceec-4138-b2AA-0C2221BE37C13
the log tells the root cause.
04-25 10:20:01.809 W/ActivityManager( 1461): Service starting has been prevented by iaware or trustsbase sInfo ServiceInfo{8882f89 com.huawei.hms.cordova.push.remote.HmsPushMessageService}
Solution is below. Just add a delay when starting
please refer to this url for more info: https://blog.katastros.com/a?ID=01750-e3e353a0-ceec-4138-b2aa-0c221be37c13