Hi i am using the gem https://github.com/PRX/apn_on_rails.git and followed the instructions to send push notifications for my iOS app.I created notifications like:
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
And run the rake command in my local server:
rake apn:notifications:deliver
to send the notifications.Everything went well but my mobile received nothing still. I checked the apn_notifications table and found the sent_at was still nil after running rake command.I saved several notifications in database but none of them were delivered (all the sent_at stayed nil).Well i got something as
$ rake apn:notifications:deliver --trace
** Invoke apn:notifications:deliver (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute apn:notifications:deliver
I included
begin
require 'apn_on_rails_tasks'
rescue MissingSourceFile => e
puts e.message
end
in my Rakefile.Is there anything I missed so that the notifications can’t be delivered?
I had the same behaviour, and for me, it turns out that I have used the incorrect PEM certificate. And once I converted the certificate from .P12 to .PEM properly, and put it in /config folder, it worked.
One way to debug it, is that instead of waiting to use RAKE to push the delivery to Apple server, you can try calling
APN::App.send_notifications
immediately after the notification.save
within your ruby/rails controller.
from the log when running it, I saw that Apple is rejecting my connection, hence I knew my cert was incorrect.