diff --git a/README.rdoc b/README.rdoc index f94e7a8..3a58066 100644 --- a/README.rdoc +++ b/README.rdoc @@ -87,6 +87,21 @@ Forcing a reconnect is as easy as calling either method with the single paramete If you're sending notifications, you should definitely call one of the receive methods periodically, as Apple's policies require it and they apparently monitors providers for compliance. I'd definitely recommend throwing together a quick rake task to take care of this for you (the {whenever library}[http://github.com/javan/whenever] provides a nice wrapper around scheduling tasks to run at certain times (for systems with cron enabled)). +Just for the record, this is essentially what you want to have whenever run periodically for you: + + def self.clear_uninstalled_applications + feedback_data = APN::Feedback.new(:environment => :production).data + + feedback_data.each do |item| + user = User.find_by_iphone_token( item.token ) + + if user.iphone_token_updated_at && user.iphone_token_updated_at > item.timestamp + return true # App has been reregistered since Apple determined it'd been uninstalled + else + user.update_attributes(:iphone_token => nil, :iphone_token_updated_at => Time.now) + end + end + end diff --git a/lib/apn/queue_manager.rb b/lib/apn/queue_manager.rb index d30ac71..013200a 100644 --- a/lib/apn/queue_manager.rb +++ b/lib/apn/queue_manager.rb @@ -5,6 +5,7 @@ module APN # Enqueues a notification to be sent in the background via the persistent TCP socket, assuming apn_sender is running (or will be soon) def self.notify(token, opts = {}) + token = token.to_s.gsub(/\W/, '') APN::QueueManager.enqueue(APN::NotificationJob, token, opts) end diff --git a/lib/apn/sender.rb b/lib/apn/sender.rb index 40610fc..41fe47a 100644 --- a/lib/apn/sender.rb +++ b/lib/apn/sender.rb @@ -45,33 +45,3 @@ def apn_port end end - - -__END__ - -# irb -r 'lib/apple_push_notification' - -## To enqueue test job -k = 'ceecdc18 ef17b2d0 745475e0 0a6cd5bf 54534184 ac2649eb 40873c81 ae76dbe8' -c = '0f58e3e2 77237b8f f8213851 c835dee0 376b7a31 9e0484f7 06fe3035 7c5dda2f' -APN.notify k, 'Resque Test' - -# If you need to really force quit some screwed up workers -Resque.workers.map{|w| Resque.redis.srem(:workers, w)} - -# To run worker from rake task -CERT_PATH=/Users/kali/Code/insurrection/certs/ ENVIRONMENT=production rake apn:work - -# To run worker from IRB -Resque.workers.map(&:unregister_worker) -require 'ruby-debug' -worker = APN::Sender.new(:cert_path => '/Users/kali/Code/insurrection/certs/', :environment => :production) -worker.very_verbose = true -worker.work(5) - -# To run worker as daemon -args = ['--environment=production', '--cert-path=/Users/kali/Code/insurrection/certs/'] -APN::SenderDaemon.new(args).daemonize - -# To run daemonized version in Rails app -./script/apn_sender --environment=production start