簡體   English   中英

解析到Firebase增強的推送通知

[英]Parse to Firebase enhanced push notifications

我正在將Parse遷移到Firebase,但在增強的推送通知方面遇到了麻煩。

解析數據(iOS端)就像:

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

使用Firebase API時, ast標簽是['notification'] ['body']

如果我發送

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

它可以完美運行並生成以下推送:

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

因此,這里的問題是,我需要在該標簽(警報)中發送字典,但由於Firebase將值設置為字符串,所以無法執行此操作。

python中的示例:

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

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

send_push()

在iOS方面,我得到:

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

始終作為字符串:S

有什么方法可以將警報發送為dict?

FCM始終將notification body參數視為String 這只是行為。 您需要做的是利用data有效負載並將其放入自定義鍵值對中:

在iOS上,如果消息是通過APNS發送的,則表示自定義數據字段。 如果通過FCM連接服務器發送,它將在AppDelegate application:didReceiveRemoteNotification:中表示為鍵值字典。

有關更多詳細信息,請參見本iOS文檔中的“ 接收消息” 我認為對於您的情況,您只需要在有效負載中同時使用notificationdata參數即可。

json.loads()應該給你一個字典。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM