消息正在发送但未收到

时间:2018-06-09 05:52:04

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

我正在使用fcm gem。

这是我的代码:

module NotificationHelper
  require 'fcm'

  def send_notification(location, message,user_id )
    firebase_key = Rails.application.secrets.firebase_key

    user = User.find_by(id: user_id)
    fcm = FCM.new(firebase_key)
    registration_ids= [user.device_token] # an array of one or more client registration tokens
    options = {:data => {"message": message, "location": location}}
    response = fcm.send(registration_ids, options)
  end
end

这是我的回答:

  

{“status_code”:200,           “回应”:“成功”,           “canonical_ids”:[],           “not_registered_ids”:[]}

1 个答案:

答案 0 :(得分:1)

将您的选项更改为以下内容:

options = {
        priority: 'high',
        data: {
            message: message,
            location: location
        },
        notification: {
            body: message,
            location: location,
            sound: 'default'
        }
    }

这对我有用。