华为推送套件API - 从通知的有效负载中读取数据 - on远程消息接收不起作用



我想从这个推送通知的有效载荷中读取日期字段,但api似乎不起作用:(

我现在来自hms华为,我已经阅读了这个教程:HMS-Plugin-Guides-V1

除d点,->覆盖错误。

当我发送通知时,我推送它。好了,我的应用会打开。但是我无法读取通知正文

在日志中我看到通知服务start ->带上token,立即自杀…我不明白问题出在哪里。

JSON通知


{
"validate_only": false,
"message": {
"notification": {
"title": "Notifica simpatica",
"body": "Io sono il body della notifica simpatica",
"notify_icon": "https://res.vmallres.com/pimages//common/config/logo/SXppnESYv4K11DBxDFc2.png"
},
"data": "{'param1':'value1','param2':'value2'}",
"android": {
"collapse_key": -1,
"urgency": "NORMAL",
"category": "PLAY_VOICE",
"ttl": "1448s",
"fast_app_target": 1,
"notification": {
"click_action": {
"type": 1,
"intent": "intent://eccc_ecc"
}
}
},
"token":-xxxxx"
]
}
}

我的应用代码:

const App = () => {

HmsPushEvent.onTokenReceived(result => {
console.log('Push token', result.token);
});

HmsPushEvent.onRemoteMessageReceived(event => {
console.log('Data message received');
const RNRemoteMessageObj = new RNRemoteMessage(event.msg);
const msg = RNRemoteMessageObj.parseMsgAllAttribute(event.msg);
console.log('Data message received : ' + msg);
});

return (
<SafeAreaView>
<Text>Testing Text</Text>
</SafeAreaView>
);
};

Manifest(仅应用程序部分,其他行是任何android应用程序的标准行):

<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<meta-data
android:name="push_kit_auto_init_enabled"
android:value="true" />
</application>

这是'浓缩'日志:

16:23:53.989 HMSSDK_HmsMessageService:开始绑定16:23:54.032 HMSSDK_HmsMessageService: handle message start16:23:54.036 HMSSDK_HmsMessageService: onNewToken16:23:54.043 HMSSDK_HmsMessageService: doOnNewToken:transactionId = null, internalCode = 0,subjectId:null,proxyType:null16:23:54.046 HMSSDK_HmsMessageService: Apply token OnNewToken, subbid: null16:23:54.179 HMSSDK_HmsMessageService: onNewToken to host app。16:23:54.215 HMSSDK_HmsMessageService: onNewToken到主机应用与bundle。16:23:54.222 HMSSDK_HmsMessageService: start to destroy

您正在尝试发送通知消息,但onRemoteMessageReceived用于接收数据消息,因此您无法读取日期字段。

通知消息的自定义字段在用户点击消息时传输到应用程序中,需要通过HmsPushEvent.onNotificationOpenedApp(callback)接收。

详细信息请参考本接口文档

你需要"通知";或";data"对象。

根据Huawei developer Push Kit Server Development Guide下行消息发送

{
"validate_only": false,
"message": {
"data": "{'param1':'value1','param2':'value2'}",
"token": ["pushtoken1"]
}}

相关内容

  • 没有找到相关文章