I've set up my rails app to send push notifications to my iphone app using this tutorial as my guide:
http://blog.thefrontiergroup.com.au/2011/05/sending-apple-push-notifications-in-rails-with-redis-and-apn_sender/
Everything seems to be running fine - but when I try to create a new notification in the console
APN.notify(my_token, :alert => "Test message", :badge => 4, :sound => true)
all it returns is an empty array! # => []
When I check for feedback
feedback = APN::Feedback.new
I get the message:
APN::Feedback: Connection not currently established to feedback.sandbox.push.apple.com on 2196
I'm connected to redis OK, it seems to be logging lots of data:
[13058] 08 Jun 16:42:03 - DB 0: 2 keys (0 volatile) in 4 slots HT. [13058] 08 Jun 16:42:03 - 0 clients connected (0 slaves), 922944 bytes in use [13058] 08 Jun 16:42:08 - DB 0: 2 keys (0 volatile) in 4 slots HT.
But (as far as I'm aware) I'm not connected to the apple server.
This is on my OSX 10.6 开发者_如何学编程development environment. Ruby 1.9.2 Rails 3.1.0.rc1
Can anybody help me troubleshoot this?
What format should the iPhone notification token be in? Base64 decoded?
Managed to fix this one - the problem seemed to be with the token format I was using.
Changed to this format:
# (regexp) /(\w{8}\s){7}(\w{8})/ # randomly generated example string f4134ff5 ec6504c2 a803da24 fb79cbcd 5243b00d d7fa625f 54c6b4ea 05768cf4
APN::Feedback: Connection not currently established to feedback.sandbox.push.apple.com on 2196
you need to call the .data method to start the connect.
feedback_data = APN::Feedback.new().data
and whenever you use a invalid toke, APNS disconnects you which might cause problems so I guess that is why your Regex makes sense. here is my regex for checking after removing spaces. Even without spaces, tokens still are accepted.
[a-zA-Z0-9]{64}
精彩评论