0

嗨,我正在使用 gem https://github.com/PRX/apn_on_rails.git并按照说明为我的 iOS 应用程序发送推送通知。我创建了如下通知:

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 仍然为零。我在数据库中保存了几个通知,但没有一个被传递(所有 sent_at 都保持为零)。好吧,我得到了一些东西

$ 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 中。我错过了什么以致无法发送通知吗?

4

1 回答 1

0

我有同样的行为,对我来说,事实证明我使用了不正确的 PEM 证书。一旦我将证书从 .P12 正确转换为 .PEM,并将其放入 /config 文件夹,它就可以工作了。


调试它的一种方法是,您可以尝试在 ruby​​/rails 控制器中的 notification.save 之后立即调用 APN::App.send_notifications ,而不是等待使用 RAKE 将交付推送到 Apple 服务器。从运行它时的日志中,我看到 Apple 拒绝了我的连接,因此我知道我的证书不正确。

于 2012-09-05T17:13:33.443 回答