![](/img/trans.png)
[英]notification push ruby on rails with firebase for ios and android
[英]Android Push Notification using firebase from ruby on rails
如何使用 ruby on rails 中的 firebase 向 Android Mobile 发送推送通知。 我知道 rails-push-notifications 和其他人,但我想使用 firebase,所以请提供有关如何在 android 应用程序中使用 firebase 发送推送通知的文档。
为我工作...
将此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)
我希望它对你有帮助。
您可以找到这个fcm gem ,它允许您使用 Firebase Cloud Messaging 发送通知。
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)
元明
不需要使用 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"
},
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.