0

我是Rails的新手。我正嘗試使用rpush寶石發送推送通知。Rpush通知未能交付

我以下步驟:

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! 

通知被保存,但沒有得到發表,我也得到了以下錯誤說明:

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

無法瞭解這裏的問題。請幫幫我。

謝謝!

+0

從此[論壇]根據(https://github.com/rpush/rpush/問題/ 96),也許你的系統中有一個無效的設備註冊ID。此消息表明通知沒有通過,因此您必須擁有另一個註冊ID,該ID對於正在通過的通知有效。您可以檢查此給定的鏈接以獲取更多可能的解決方法。另外請確保你[device_token](https://github.com/rpush/rpush/issues/27)是正確的。 – abielita

回答

0

當你發現以上在日誌中提到的消息,意味着,作爲所述@abielita和rpush wiki文檔中,identification_id GCM用來發送通知,不再有效

作爲註冊令牌的設備(d.device_token)未在GCM(Firebase)服務上註冊。

此消息出於特定原因:使您的代碼適應此情況。

也許是更好的銷燬你的「d」記錄!?

變爲有用Rpush.reflect配置/初始化/ rpush.rb

取消註釋事件通知on.gcm_invalid_registration_id並添加內部塊 例如代碼

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

和封閉條件檢查裏面你發送通知代碼

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 

我希望它幫