Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby apns gem returns nil

I'm trying to get the APNS gem to work with my Rails app. I had originally set this up several months ago, and push notifications to iOS devices worked swimmingly. Now, my app is live and I've found that notifications aren't going out anymore. The APNS gem hasn't been updated in some time, so I've tried various later forks of it, all to the same effect.

Here's what I'm doing:

APNS.host = 'gateway.push.apple.com' 
APNS.pem  = Rails.root + "lib/push_production.pem"
APNS.port = 2195 
APNS.send_notification(device_token, "Test send" )

And the result?

=> nil

There's no feedback from any method, no logfile that I can check. I've tried generating and regenerating my certificate; everything seems okay there. I've tried expressing my device token in various ways, without the angle brackets, without spaces between groups of characters... APNS don't care.

Given the number of moving parts involved in this, I know this is a tough question. But can anyone suggest where to look?

like image 869
Aaron Vegh Avatar asked Nov 18 '12 03:11

Aaron Vegh


1 Answers

The official documentation says this :

If you send a notification and APNs finds the notification malformed or otherwise unintelligible, it returns an error-response packet prior to disconnecting. (If there is no error, APNs doesn’t return anything.) Figure 5-3 depicts the format of the error-response packet.

So it only makes sense that the gem doesn't return anything, because Apple's server doesn't let it know what it's doing. Also if you look at the gem's github page, the given examples do not handle the return value of APNS.send_notification.

Last time I worked with Apple Push Notifications, it pretty much behaved like a black box, not returning anything most of the time.

like image 160
Raf Avatar answered Sep 19 '22 23:09

Raf