Ruby apns gem returns nil
apple-push-notifications, ios, ruby-on-rails
Solution
I believe I've found the answer. After registering an account with Urban Airship, I tried sending a test message to my phone, and again to no avail. But these guys actually have their act together, so they were able to show me the error message! Turns out my device token was invalid. Why? Because it was generated by the sandboxed version of the app.
Yes, my app is in the store, but it turns out that my App Store distribution profile was generated before the push notification entitlement was added to it. So when you run the codesign tool on my executable, it doesn't show the entitlement. Here's an example:
Diomedes:Release-iphoneos aaron$ codesign -dvvvv --entitlements - Tiberius.app
That command should show a plist that contains the key with a value of "production". My release didn't have that key at all.
I was actually forced to generate an all-new distribution profile in the Provisioning Portal, which finally did include the correct entitlements. I haven't been able to test this yet (8 day App Store review, anyone?) but I feel like this is the problem.
P.S. This article on Urban Airship's site was instrumental in helping me.
Problem
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?