簡體   English   中英

使用來自 ruby​​ on rails 的 firebase 的 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)

更多關於 gem fcm

我希望它對你有幫助。

您可以找到這個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.

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