我需要发送推送通知到IOS手机。
我使用apn_on_rails发送此通知。
我从IOS developer那里获得了我的pem文件。我对它做了以下配置
在config/configtran/*..rb中进行生产和开发
RAILS_ROOT, APN::App::RAILS_ENV='production'
configatron.apn.passphrase = 'leo_123'
configatron.apn.port = 2195
configatron.apn.host = 'gateway.sandbox.push.apple.com'
configatron.apn.cert = File.join(Rails.root, 'config', ' apple_push_notification_development.pem')然后,我根据文档创建了一个Notificationby。
在我运行以下命令之后,它处于理想状态并进行响应
从控制台
APN::App.send_notifications
使用rake RAILS_ENV=production rake apn:通知:传递
我在生产环境和开发环境中都尝试过这一点。折叠线之后它就没有反应了。我也没在日志里找到任何东西。
APN::App Load (0.1ms) SELECT "apn_apps".* FROM "apn_apps"我还没有在任何云服务器上托管这个应用程序。这个应用程序是否应该托管在任何云服务器中才能正常工作?
任何帮助都很感激。
发布于 2014-06-09 14:09:26
使用grocer gem更容易。
pusher = Grocer.pusher(certificate: "#{Rails.root}/lib/dev_cert.pem", # required
passphrase: "XXXXXX", # optional
gateway: "gateway.sandbox.push.apple.com", # optional
port: 2195, #optional
retries: 3)
feedback = Grocer.feedback( certificate: "#{Rails.root}/lib/dev_cert.pem",
passphrase: "XXXXXX",
gateway: "feedback.sandbox.push.apple.com",
port: 2196,
retries: 3)
notification = Grocer::Notification.new(
device_token: push_id,
alert: message,
badge: 3,
sound: "siren.aiff", # optional
expiry: Time.now + 60*60, # optional; 0 is default, meaning the message is not stored
# identifier: 1234, # optional
content_available: true # optional; any truthy value will set 'content-available' to 1
)
feedback.each do |attempt|
puts "Device #{attempt.device_token} failed at #{attempt.timestamp}"
end
pusher.push(notification)https://stackoverflow.com/questions/24121197
复制相似问题