1

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

我现在来自 hms 华为,我已经阅读了这个教程: 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:开始绑定
16:23:54.032 HMSSDK_HmsMessageService:处理消息启动
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:应用令牌 OnNewToken,subId:null
16:23:54.179 HMSSDK_HmsMessageService: onNewToken 来托管应用程序。
16:23:54.215 HMSSDK_HmsMessageService:onNewToken 以使用捆绑软件托管应用程序。
16:23:54.222 HMSSDK_HmsMessageService:开始销毁
4

1 回答 1

0

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

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

更多详细信息,请参考此接口文档

于 2021-10-02T12:05:15.317 回答