使用Rpush Gem Ruby on Rails向App发送通知

时间:2014-06-11 11:15:02

标签: ios ruby-on-rails ruby gem

我正在尝试使用Rpush Gem在我的应用中实现推送通知。 到目前为止,我已经尝试过了。

    if @push_notification.present?
    else
      app = Rpush::Apns::App.new
      app.name = "ios_app"
      app.certificate = File.read("config/apns-dev.pem")
      app.environment = "development" # APNs environment.
      app.password = ""
      app.connections = 1
      app.save! 
    end

    n = Rpush::Apns::Notification.new
    n.app = Rpush::Apns::App.find_by_name("ios_app")
    n.device_token = session[:push_notification_token]
    n.alert = "hi im alert!"
    n.data = { foo: :bar }
    n.save!

这会向数据库保存通知。我想知道如何发送此通知。

1 个答案:

答案 0 :(得分:1)

使用rpush这应该是实际发送推送消息。您的证书可能没有正确设置,或者推送令牌不正确,或者您可能尚未启动rpush。你在堆栈的某个地方调用Rpush.embed吗?我把它放在config.ru