我正在使用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”:[]}
答案 0 :(得分:1)
将您的选项更改为以下内容:
options = {
priority: 'high',
data: {
message: message,
location: location
},
notification: {
body: message,
location: location,
sound: 'default'
}
}
这对我有用。