简体   繁体   中英

notification push ruby on rails with firebase for ios and android

hello I'm looking for a gem for push notifications from ruby ​​in rails with firebase, I'm actually very new to notifications and the mobile devices I appreciate any help. I'm finishing a project and I just need that in the back-end.

I would like, for example, every time a service is registered by the client within the mobile app, I will generate a push notification where it says "a new service has been generated" and that all employees can see it

Hey you can use the rpush gem it's really easy to handle and very explanatory documentation I have been using this for a while and never faced any issue with it. We can easliy handle the ios/android notification by the single gem.

First you need install rpush and run this command bundle exec rpush init

Now write down a task to to add the firebase api-key

app = Rpush::Gcm::App.new
app.name = "android_app"
app.auth_key = "..."
app.connections = 1
app.save!

whenever you need to send the notification you need to use this method to push the notification in the notification table

n = Rpush::Gcm::Notification.new n.app = Rpush::Gcm::App.find_by_name("android_app")
n.registration_ids = ["..."]
n.data = { message: "hi mom!" }
n.priority = 'high'        # Optional, can be either 'normal' or 'high'
n.content_available = true # Optional
you can use!
n.notification = { body: 'great match!',
                   title: 'Portugal vs. Denmark',
                   icon: 'myicons'
                 }
n.save!

add this in application controller and call this method everywhere in the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM