san*_*osh 4 ruby ruby-on-rails push-notification apple-push-notifications ios
我需要向IOS mobile发送推送通知.
我使用apn_on_rails发送此通知.
我从IOS开发者处获取了我的pem文件.我做了以下配置
在config/configtran/*.rb中的Productions和开发中
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')
Run Code Online (Sandbox Code Playgroud)
然后我按照文档创建了一个Notificationby.
在我运行以下命令后,它是理想的并且响应
从控制台
APN :: App.send_notifications
使用rake RAILS_ENV = production rake apn:notifications:deliver
我在生产和开发环境中都尝试过这种方法.在下面的行之后,它没有响应.我也没有在Log中找到任何东西.
APN::App Load (0.1ms) SELECT "apn_apps".* FROM "apn_apps"
Run Code Online (Sandbox Code Playgroud)
我没有在任何云服务器上托管此应用程序.此应用程序是否应该在任何云服务器中托管以正确使用应用程序?
任何帮助赞赏.
与杂货店宝石合作更容易.
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5635 次 |
| 最近记录: |