APNS休斯顿宝石转向配置文件

时间:2015-03-11 23:49:52

标签: ruby-on-rails gem

我想将以下行移至我的development.rbproduction.rb,因此我不需要在生产和开发中更改证书路径(减少合并冲突)。现在它们在我的控制器中定义,但将它们移动到我的config文件夹却什么也没做。我这样做了吗?

development.rb

APN = Houston::Client.development
APN.certificate = File.read("/path/to/apple_push_notification.pem")

然后在我的控制器中

         notification = Houston::Notification.new(device: phone.device_token)
         notification.alert = "Push me!"
         notification.sound = "default"
         notification.badge = 1
         APN.push(notification)

https://github.com/nomad/Houston

1 个答案:

答案 0 :(得分:0)

您不需要在开发和生产中移动这些文件

您甚至可以通过检查环境

放入控制器来完成此操作
if Rails.env.development?
  APN = Houston::Client.development
  APN.certificate = File.read("/path/to/apple_push_notification.pem")
elsif Rails.env.production?
  APN = Houston::Client.production  ## ALL you have to change this to production
  APN.certificate = File.read("/path/to/apple_push_notification.pem")
end