当我使用console.firebase.com时,我可以向$ RECIPIENT发送推送通知。 如果我使用spacialdb/fcm发送,则不会发送推送。即使服务器的回复看起来不错。 => (:status_code => 200,:response =>“成功”)
知道可能出错的是什么?
码
require 'fcm'
fcm = FCM.new('$TOKEN')
registration_ids = ['$RECIPIENT']
options = { data: { score: '123' }, collapse_key: 'updated_score' }
response = fcm.send(registration_ids, options)
puts "Sendt: #{response}"
正在运行的代码
$ ruby fcm.rb
Sendt: {:body=>"{\"multicast_id\":60356242858746826,\"success\":1,\"failure\":0,
\"canonical_ids\":0,
\"results\":[{\"message_id\":\"0:1528896392320437%e06a962bca0e\"}]}",
:headers=>{"content-type"=>["application/json; charset=UTF-8"],
"date"=>["Wed, 13 Jun 2018 13:26:32 GMT"], "expires"=>["Wed, 13 Jun 2018 13:26:32 GMT"], "cache-control"=>["private, max-age=0"],
"x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"],
"x-xss-protection"=>["1; mode=block"],
"server"=>["GSE"], "alt-svc"=>["quic=\":443\"; ma=2592000; v=\"43,42,41,39,35\""],
"accept-ranges"=>["none"], "vary"=>["Accept-Encoding"],
"connection"=>["close"]}, :status_code=>200, :response=>"success",
:canonical_ids=>[], :not_registered_ids=>[]}
答案 0 :(得分:0)
github.com/spacialdb/fcm上的示例推送代码只是发送一个数据推送。由于未将iPhone应用程序配置为收听,所以看不到收到任何声音。
要发送推送通知,您需要遵循以下语法:
# See https://developers.google.com/cloud-messaging/http for more details.
fcm = FCM.new("API_KEY")
fcm.send(
registration_ids: ["4sdsx", "8sdsd"],
{ "notification":
{ "title": "Portugal vs. Denmark",
"text": "5 to 1"
},
}
)
我在fcm处创建了PR to update the docs。希望他们会接受并让下一个家伙更轻松。 :-)