Skip to content
Newer
Older
100644 104 lines (66 sloc) 3.34 KB
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
1 =APN on Rails (Apple Push Notifications on Rails)
2
3 APN on Rails is a Ruby on Rails gem that allows you to easily add Apple Push Notification (iPhone)
4 support to your Rails application.
5
6 ==Acknowledgements:
85e318a @markbates Added tests for the apple_hash method
markbates authored Jul 23, 2009
7
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
8 This gem is a re-write of a plugin that was written by Fabien Penso and Sam Soffes.
9 Their plugin was a great start, but it just didn't quite reach the level I hoped it would.
10 I've re-written, as a gem, added a ton of tests, and I would like to think that I made it
11 a little nicer and easier to use.
85e318a @markbates Added tests for the apple_hash method
markbates authored Jul 23, 2009
12
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
13 ==Converting Your Certificate:
14
85e318a @markbates Added tests for the apple_hash method
markbates authored Jul 23, 2009
15 Once you have the certificate from Apple for your application, export your key
16 and the apple certificate as p12 files. Here is a quick walkthrough on how to do this:
17
18 1. Click the disclosure arrow next to your certificate in Keychain Access and select the certificate and the key.
19 2. Right click and choose `Export 2 items...`.
20 3. Choose the p12 format from the drop down and name it `cert.p12`.
21
22 Now covert the p12 file to a pem file:
23
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
24 $ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts
25
26 Put 'apple_push_notification_production.pem' in config/
85e318a @markbates Added tests for the apple_hash method
markbates authored Jul 23, 2009
27
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
28 If you are using a development certificate, then change the name to apple_push_notification_development.pem instead.
85e318a @markbates Added tests for the apple_hash method
markbates authored Jul 23, 2009
29
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
30 ==Installing:
31
32 ===Stable (RubyForge):
85e318a @markbates Added tests for the apple_hash method
markbates authored Jul 23, 2009
33
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
34 $ sudo gem install apn_on_rails
35
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
36 ===Edge (GitHub):
37
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
38 $ sudo gem install markbates-apn_on_rails --source=http://gems.github.com
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
39
40 ===Rails Gem Management:
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
41
42 If you like to use the built in Rails gem management:
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
43
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
44 config.gem 'apn_on_rails'
45
46 Or, if you like to live on the edge:
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
47
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
48 config.gem 'markbates-apn_on_rails', :lib => 'apn_on_rails', :source => 'http://gems.github.com'
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
49
50 ==Setup and Configuration:
51
52 Once you have the gem installed via your favorite gem installation, you need to require it so you can
53 start to use it:
54
55 Add the following require, wherever it makes sense to you:
56
57 require 'apn_on_rails'
58
59 You also need to add the following to your Rakefile so you can use the
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
60 Rake tasks that ship with APN on Rails:
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
61
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
62 begin
63 require 'apn_on_rails_tasks'
64 rescue MissingSourceFile => e
65 puts e.message
66 end
67
68 Now, to create the tables you need for APN on Rails, run the following task:
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
69
7f2d342 @markbates Updated README
markbates authored Jul 26, 2009
70 $ ruby script/generate apn_migrations
85e318a @markbates Added tests for the apple_hash method
markbates authored Jul 23, 2009
71
525710c @markbates Updated README
markbates authored Jul 24, 2009
72 APN on Rails uses the Configatron gem, http://github.com/markbates/configatron/tree/master,
73 to configure itself. APN on Rails has the following default configurations that you change as you
74 see fit:
75
76 configatron.apn.passphrase # => ''
77 configatron.apn.port # => 2195
78 configatron.apn.host # => 'gateway.sandbox.push.apple.com'
79 configatron.apn.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_development.pem')
80
81 # production:
82 configatron.apn.host # => 'gateway.push.apple.com'
83 configatron.apn.cert #=> File.join(RAILS_ROOT, 'config', 'apple_push_notification_production.pem')
84
68ae1d8 @markbates Added documentation.
markbates authored Jul 23, 2009
85 That's it, now you're ready to start creating notifications.
85e318a @markbates Added tests for the apple_hash method
markbates authored Jul 23, 2009
86
8fc4bf8 @markbates Finished documentation.
markbates authored Jul 24, 2009
87 ==Example:
88
89 $ ./script/console
90 >> device = APN::Device.create(:token => "XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX")
91 >> notification = APN::Notification.new
92 >> notification.device = device
93 >> notification.badge = 5
94 >> notification.sound = true
95 >> notification.alert = "foobar"
96 >> notification.save
97 >> APN::Notification.send_notifications
98
99 You can also run the following Rake task to send your notifications:
100
101 $ rake apn:notifications:deliver
525710c @markbates Updated README
markbates authored Jul 24, 2009
102
103 Released under the MIT license.
Something went wrong with that request. Please try again.