您好我正在使用gem https://github.com/PRX/apn_on_rails.git并按照说明为我的iOS app发送推送通知。我创建了以下通知:
device = APN::Device.create(:token => "XXXX XXXX XXXXX XXXX XXXX .... XXXX")
notification = APN::Notification.new
notification.device = device
notification.badge = 5
notification.sound = true
notification.alert = "My first push"
notification.save
在我的本地服务器上运行rake命令:
rake apn:notifications:deliver
发送通知。一切顺利,但我的手机仍未收到任何信息。我检查了apn_notifications表,发现在运行rake命令后sent_at仍然是nil。我在数据库中保存了几个通知,但没有一个被传递(所有sent_at都保持为nil)。我得到的东西是
$ rake apn:notifications:deliver --trace
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
我包括
begin
require 'apn_on_rails_tasks'
rescue MissingSourceFile => e
puts e.message
end
在我的Rakefile中。是否有任何我错过的内容,以致无法发送通知?
答案 0 :(得分:0)
我有同样的行为,对我来说,事实证明我使用了错误的PEM证书。一旦我将.P12中的证书正确转换为.PEM,并将其放在/ config文件夹中,就可以了。
调试它的一种方法是,不是等待使用RAKE将传递推送到Apple服务器,而是可以尝试调用
APN :: App.send_notifications
在notification.save之后立即
你的ruby / rails控制器内。
从日志中运行它时,我看到Apple拒绝我的连接,因此我知道我的证书不正确。