Dharmil
Dharmil

Reputation: 63

Rpush notification fails to deliver

I am new to Rails. I am trying to send push notification using rpush gem.

I am following these steps:

n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("android_app")
n.registration_ids = ["#{d.device_token}"]
n.data = { title: "#{self.title}"}
n.save!

The notification gets saved but is not getting delivered, and I get the following error description:

"Unable to deliver notification 10, received error (Failed to deliver to all recipients. Errors: NotRegistered.)"

Not able to understand the issue here. Please help me.

Thanks!

Upvotes: 1

Views: 1848

Answers (1)

rfellons
rfellons

Reputation: 666

When you find above mentioned message in your log, means, as said @abielita and rpush wiki documentation, the identification_id GCM is using to send notification, is no more valid.

Device with (d.device_token) as registration token, is no more registered on GCM (Firebase) Service.

This message come for a specified reason: adapt your code to this condition.

Maybe is better destroy your "d" record !?

Becomes helpful Rpush.reflect in config/initializers/rpush.rb

Uncomment event notification on.gcm_invalid_registration_id and add your code inside block e.g.

on.gcm_invalid_registration_id do |app, error, registration_id|
  Device.where(registration_id: registration_id).take.destroy
end

and encloses your sending notification code inside a conditional check

unless(d.nil?)
  n = Rpush::Gcm::Notification.new
  n.app = Rpush::Gcm::App.find_by_name("android_app")
  n.registration_ids = ["#{d.device_token}"]
  n.data = { title: "#{self.title}"}
  n.save!
end

I hope it help

Upvotes: 2

Related Questions