【问题标题】:problems sending Firebase message with data发送带有数据的 Firebase 消息时出现问题
【发布时间】:2019-01-15 03:26:45
【问题描述】:

我能够使用 pyfcm 成功发送标题/文本消息:

result = push_service.notify_multiple_devices(registration_ids=registration_tokens, message_title="title",
                                                  message_body="testing")

但是当我尝试发送数据消息时,它失败了:

    payload = {
        'action': 'testing',
        'test number': 1,
        'question': "what do you do with a klondike bar?",
    }
    result = push_service.multiple_devices_data_message(registration_ids=registration_tokens, data_message=payload)

在第一种情况下,我按预期通过 onMessageReceived 方法在电话上的 FirebaseMessagingService 中接收文本/消息。在第二种情况下(字典数据负载),它永远不会被接收到:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    RemoteMessage.Notification data = remoteMessage.getNotification();
    System.out.print("here");
}

在这两种情况下,结果似乎都是成功的。

欢迎提出任何建议!

【问题讨论】:

  • 你能打印出第二种情况下payload的实际值吗?
  • payload = { 'action': 'testing', 'test number': 1, 'question': "你用克朗代克酒吧做什么?", }
  • Err... 负载项不应该包含在 notificationdata 父级中吗?
  • 我按照pypi.org/project/pyfcm 的指示进行操作。没有提及通知或数据父级。

标签: python firebase firebase-cloud-messaging pyfcm


【解决方案1】:

multiple_devices_data_message好像有问题

我试过了:

result = push_service.single_device_data_message(registration_id=registration_tokens[0], data_message=payload)

它按预期工作。所以现在要解决我的问题,我需要遍历每个注册令牌,为每个令牌调用 single_device_data_message

【讨论】:

    猜你喜欢
    • 2021-10-21
    • 2019-01-19
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多