![](/img/trans.png)
[英]Huawei Push Kit API - Read in background push data message with react native
[英]Huawei Push Kit API - Read data from payload of Notifications - onRemoteMessageReceived don't work
我想從這個推送通知的有效負載中讀取日期字段,但 api 似乎不起作用:(
我現在來自hms Huawei,我已經閱讀了這個教程: HMS-Plugin-Guides-V1
除 d 點外,其他部分均已完成,-> 覆蓋錯誤。
當我發送通知時,我會推送它。 一切正常,我的應用程序將打開。 但我無法閱讀通知正文。
在日志中,我看到通知服務啟動 -> 獲取令牌並立即自行終止......我不明白問題出在哪里。
通知 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>
);
};
清單(僅應用程序部分,其他行是任何 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: start to bind 16:23:54.032 HMSSDK_HmsMessageService: handle message start 16:23:54.036 HMSSDK_HmsMessageService: onNewToken 16:23:54.043 HMSSDK_HmsMessageService: doOnNewToken:transactionId = null , internalCode = 0,subjectId:null,proxyType:null 16:23:54.046 HMSSDK_HmsMessageService: Apply token OnNewToken, subId: null 16:23:54.179 HMSSDK_HmsMessageService: onNewToken to host app. 16:23:54.215 HMSSDK_HmsMessageService: onNewToken to host app with bundle. 16:23:54.222 HMSSDK_HmsMessageService: start to destroy
您正在嘗試發送通知消息,但onRemoteMessageReceived
用於接收數據消息,因此您無法讀取日期字段。
通知消息的自定義字段在用戶點擊消息時傳遞給應用,需要通過HmsPushEvent.onNotificationOpenedApp(callback)
接收。
更多詳細信息,請參閱此接口文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.