简体   繁体   English

解析到Firebase增强的推送通知

[英]Parse to Firebase enhanced push notifications

I'm migrating Parse to Firebase and I'm having trouble with the enhanced push notification. 我正在将Parse迁移到Firebase,但在增强的推送通知方面遇到了麻烦。

Parse data (iOS side) was like: 解析数据(iOS端)就像:

{"ast":
  {"alert": {
    {"body": "body_test",
     "title": "title_test",
     "description": "description",
     "endpoint-proposal": "https://.."
     "launch-image": "https://..."
  },
  "sound": "chime",
  ... 
}

Working with Firebase API the ast tag is the ['notification']['body'] . 使用Firebase API时, ast标签是['notification'] ['body']

If I send 如果我发送

['notification']['body'] = 'Hello' 

It works perfectly and generate the following push: 它可以完美运行并生成以下推送:

{"ast":
  {"alert": "Hello"}
}...

So, here the problem, I need to send a dictionary in that tag (alert) and I cannot do that because firebase set the value as string. 因此,这里的问题是,我需要在该标签(警报)中发送字典,但由于Firebase将值设置为字符串,所以无法执行此操作。

Example in python: python中的示例:

alert = dict()
alert['title'] = 'title'
alert['description'] = 'description'
alert['endpoint-proposal'] = 'https://..'
alert['launch-image'] = 'https://..'

fcm_payload['notification']['body'] = alert 

send_push()

And in the iOS side I get: 在iOS方面,我得到:

[AnyHashable("gcm.message_id"): 0:123456789,
 AnyHashable("aps"): {
    alert = "{\"body\": \"body\",
              \"launch-image\": \"https://...\",
              \"endpoint-proposal\": \"https://...\",
              \"description\": \"description\",
              \"title\": \"title\"}";
}]

Always as string :S 始终作为字符串:S

Is there any way to send that alert as dict? 有什么方法可以将警报发送为dict?

The notification body parameter will always be treated by FCM as a String . FCM始终将notification body参数视为String It's just the behavior. 这只是行为。 What you'll have to do is make use of the data payload and put in your custom key-value pairs: 您需要做的是利用data有效负载并将其放入自定义键值对中:

On iOS, if the message is sent via APNS, it represents the custom data fields. 在iOS上,如果消息是通过APNS发送的,则表示自定义数据字段。 If it is sent via FCM connection server, it would be represented as key value dictionary in AppDelegate application:didReceiveRemoteNotification: . 如果通过FCM连接服务器发送,它将在AppDelegate application:didReceiveRemoteNotification:中表示为键值字典。

More details can be seen in this Receiving Messages in iOS doc. 有关更多详细信息,请参见本iOS文档中的“ 接收消息” I think for your case, you just have to use the notification and data parameters together in your payload. 我认为对于您的情况,您只需要在有效负载中同时使用notificationdata参数即可。

json.loads()应该给你一个字典。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM