Skip to content

Commit

Permalink
Documentation tweaks + strip illegal characters from token
Browse files Browse the repository at this point in the history
  • Loading branch information
kdonovan committed Jun 1, 2010
1 parent 3c352e1 commit e6e3556
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
15 changes: 15 additions & 0 deletions README.rdoc
Expand Up @@ -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 <code>receive</code> 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



Expand Down
1 change: 1 addition & 0 deletions lib/apn/queue_manager.rb
Expand Up @@ -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

Expand Down
30 changes: 0 additions & 30 deletions lib/apn/sender.rb
Expand Up @@ -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

0 comments on commit e6e3556

Please sign in to comment.