【问题标题】:Android Push Notification using firebase from ruby on rails使用来自 ruby on rails 的 firebase 的 Android 推送通知
【发布时间】:2021-02-01 17:25:04
【问题描述】:
如何使用 ruby on rails 的 firebase 向 Android Mobile 发送推送通知。我知道 rails-push-notifications 和其他人,但我想使用 firebase,所以请提供有关如何在 android 应用程序中使用 firebase 发送推送通知的文档。
【问题讨论】:
标签:
android
ruby-on-rails
ruby-on-rails-4
push-notification
【解决方案1】:
为我工作...
将此gem 'fcm' 添加到您的gemfile 中,运行命令bundle install。
创建一个方法并粘贴:
require 'fcm'
fcm = FCM.new(server_key) # Find server_key on: your firebase console on web > tab general > web api key
registration_ids= [device_keys] # Array of keys generated by firebase for devices
options = {
priority: "high",
collapse_key: "updated_score",
notification: {
title: "Message Title",
body: "Hi, Worked perfectly",
icon: "myicon"}
}
response = fcm.send(registration_ids, options)
more about gem fcm
希望对你有帮助。
【解决方案2】:
您可以找到这个fcm gem,它允许您使用 Firebase 云消息传递发送通知。
require 'fcm'
fcm = FCM.new("my_api_key")
# you can set option parameters in here
# - all options are pass to HTTParty method arguments
# - ref: https://github.com/jnunemaker/httparty/blob/master/lib/httparty.rb#L29-L60
# fcm = FCM.new("my_api_key", timeout: 3)
registration_ids= ["12", "13"] # an array of one or more client registration tokens
options = {data: {score: "123"}, collapse_key: "updated_score"}
response = fcm.send(registration_ids, options)
YM
【解决方案3】:
不需要使用 Gem,它不适用于我的应用程序。但我正在使用 React 使用具有以下标头内容的 POST 方法 (https://fcm.googleapis.com/fcm/send):
{
server_key: web_api_key_on_console_web
},
body: {
to: Mobile_token_created_by_phone,
notification: {
title: "Judul",
body: "Isi pesan"
},
}