jpoz-apns 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/MIT-LICENSE +22 -0
  2. data/README.textile +83 -0
  3. data/Rakefile +53 -0
  4. data/lib/apns.rb +1 -0
  5. metadata +56 -0
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009 James Pozdena
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ h2. Apple Push Notification Service
2
+
3
+ h3. Install
4
+
5
+ gem sources -a http://gems.github.com
6
+
7
+ sudo gem install jpoz-apns
8
+
9
+
10
+ h3. Setup:
11
+
12
+ Set what host, port, pem file and password on the APNS class:
13
+
14
+ <pre>
15
+ <code>
16
+ APNS.host = 'gateway.push.apple.com'
17
+ # gateway.sandbox.push.apple.com is default
18
+
19
+ APNS.port = 2195
20
+ # this is also the default. Shouldn't ever have to set this, but just Apple goes crazy, you can.
21
+
22
+ APNS.pem = '/path/to/pem/file'
23
+ # openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts
24
+
25
+ APNS.pass = 'secret'
26
+ </code>
27
+ </pre>
28
+
29
+ h3. Example:
30
+
31
+ Then to send a push notification you can either just send a string as the alert or give it a hash for the alert, badge and sound.
32
+
33
+ <pre>
34
+ <code>
35
+ device_token = '123abc456def'
36
+
37
+ APNS.send_notification(device_token, 'Hello iPhone!' )
38
+
39
+ APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')
40
+ </code>
41
+ </pre>
42
+
43
+ h3. Send other info along with aps
44
+
45
+ You can send other application specific information as well.
46
+
47
+ <pre>
48
+ <code>
49
+ APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default',
50
+ :other => {:sent => 'with apns gem'})
51
+ </code>
52
+ </pre>
53
+
54
+ This will add the other hash to the same level as the aps hash:
55
+
56
+ <pre>
57
+ <code>
58
+ {"aps":{"alert":"Hello iPhone!","badge":1,"sound":"default"},"sent":"with apns gem"}
59
+ </code>
60
+ </pre>
61
+
62
+
63
+ h3. Getting your iPhone's device token
64
+
65
+ After you setup push notification for your application with Apple. You need to ask Apple for you application specific device token.
66
+
67
+ ApplicationAppDelegate.m
68
+ <pre>
69
+ <code>
70
+ - (BOOL)application:(UIApplication *)application
71
+ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
72
+ {
73
+ [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];
74
+ }
75
+
76
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
77
+ NSLog(@"deviceToken: %@", deviceToken);
78
+ }
79
+ </code>
80
+ </pre>
81
+
82
+
83
+
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
5
+ require 'spec/rake/spectask'
6
+
7
+ GEM = 'apns'
8
+ GEM_NAME = 'apns'
9
+ GEM_VERSION = '0.0.1'
10
+ AUTHORS = ['James Pozdena']
11
+ EMAIL = "jpoz@jpoz.net"
12
+ HOMEPAGE = "http://github.com/jpoz/apns"
13
+ SUMMARY = "Simple Apple push notification service gem"
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = GEM
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = ["MIT-LICENSE"]
21
+ s.summary = SUMMARY
22
+ s.description = s.summary
23
+ s.authors = AUTHORS
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+ s.require_path = 'lib'
27
+ s.autorequire = GEM
28
+ s.files = %w(MIT-LICENSE README.textile Rakefile) + Dir.glob("{lib}/**/*")
29
+ end
30
+
31
+ task :default => :spec
32
+
33
+ desc "Run specs"
34
+ Spec::Rake::SpecTask.new do |t|
35
+ t.spec_files = FileList['spec/**/*_spec.rb']
36
+ t.spec_opts = %w(-fs --color)
37
+ end
38
+
39
+ Rake::GemPackageTask.new(spec) do |pkg|
40
+ pkg.gem_spec = spec
41
+ end
42
+
43
+ desc "install the gem locally"
44
+ task :install => [:package] do
45
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
46
+ end
47
+
48
+ desc "create a gemspec file"
49
+ task :make_spec do
50
+ File.open("#{GEM}.gemspec", "w") do |file|
51
+ file.puts spec.to_ruby
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ require 'apns/core'
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jpoz-apns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - James Pozdena
8
+ autorequire: apns
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Simple Apple push notification service gem
17
+ email: jpoz@jpoz.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - MIT-LICENSE
24
+ files:
25
+ - MIT-LICENSE
26
+ - README.textile
27
+ - Rakefile
28
+ - lib/apns.rb
29
+ has_rdoc: true
30
+ homepage: http://github.com/jpoz/apns
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.2.0
52
+ signing_key:
53
+ specification_version: 2
54
+ summary: Simple Apple push notification service gem
55
+ test_files: []
56
+