【发布时间】:2015-02-15 22:24:32
【问题描述】:
所以我尝试使用 rpush 来使用这个 gem 来推送我的移动应用程序的通知:https://github.com/rpush/rpush。我正在使用 sinatra 框架。但是我一直收到这个错误,即使我在文件顶部写了 --> require 'rpush' 。有红宝石经验的人可以帮助我吗?我是红宝石的新手,所以请多多包涵。这是我的代码
require 'rpush'
Module Notifier
def rpush_client
app = Rpush::Gcm::App.new
app.name = "App-Name"
app.auth_key = "XXXXXXXXXXXXXXX"
app.connections = 1
app.save!
end
def notify(user_id,alert)
rpush_client
session = db_find_one('dbname.sessions',{user_id: user_id})
if session.present?
device = session['devices'].first
token = device['device_token']
n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("App-Name")
n.registration_ids = ["token", token]
n.data = { message: alert }
n.save!
Rpush.push
end
end
end
我知道这是一个愚蠢的问题,但厌倦了在这里寻找它。
【问题讨论】:
标签: android notifications gem sinatra push