Your SlideShare is downloading. ×
How to build a server and a iPhone client application using the Apple Push Notification Service
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

How to build a server and a iPhone client application using the Apple Push Notification Service

13,185
views

Published on

Apple Push Notification Serviceを利用したiPhone クライアントと、Rubyによるサーバの作成。

Apple Push Notification Serviceを利用したiPhone クライアントと、Rubyによるサーバの作成。

Published in: Technology

0 Comments
12 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
13,185
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
111
Comments
0
Likes
12
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. How to build a server and a iPhone client application using the Apple Push Notification Service 2009/7/21 @ actindi Shu MASUDA
  • 2. 2 Apple Push Notification Service (APNs) What is the Apple Push Notification Service? ‣ iPhone OS 3.0 ‣ 3 • Alert • Badge • Sound ‣
  • 3. 3 Client Implementation Overview ★ APNs • UIApplication registerForRemoteNotificationTypes: • UIApplication application:didRegisterForRemoteNotificationsWithDeviceToken: Device Token ★ APNs • UIApplicationDelegate application:didReceiveRemoteNotification: • UIApplication Delegate applicationDidFinishLaunching:
  • 4. 4 Client Implementation • Xcode
  • 5. 5 Server Implementation Overview 1. App ID 2. 3. Interface APNS 4. Ruby
  • 6. 6 Generating App ID Bundle Identifier ”*”
  • 7. 6 Generating App ID Enable for Apple Push Notification service
  • 8. 6 Generating App ID Enable for Apple Push Notification service
  • 9. 7 Generating Key 1. p12 pem • openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12 • openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev- key.p12 2. 1. • openssl rsa -in apns-dev-key.pem -out apns-dev-key- noenc.pem 3. • cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem 4. OpenSSL • openssl s_client -connect gateway.sandbox.push.apple.com: 2195 -prexit -state -cert apns-dev-cert.pem -key apns-dev- key-noenc.pem
  • 10. 8 Creating the Push Notification Interface • Binary format of the push notification interface • (payload) JSON { “aps”: { “alert”: “You’ve got a mail!”, “badge”: 1, “sound”: “default” } }
  • 11. 9 Implementation in Ruby ★ Ruby • pack? unpack?? or ... ??? •
  • 12. 10 Implementation in Ruby #! /usr/bin/env ruby # -*- encoding: utf-8 -*- require 'socket' require 'openssl' socket = TCPSocket.new('gateway.sandbox.push.apple.com', 2195) context = OpenSSL::SSL::SSLContext.new('SSLv3') context.cert = OpenSSL::X509::Certificate.new(File.read('apns-dev.pem')) context.key = OpenSSL::PKey::RSA.new(File.read('apns-dev-key-noenc.pem')) ssl = OpenSSL::SSL::SSLSocket.new(socket, context) ssl.connect device_token = ['XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'] payload = <<-EOS { "aps": { "alert": "#{alert}", "badge": 2, “sound”: “default” } } EOS (message = []) << ['0'].pack('H') << [32].pack('n') << device_token.pack('H*') << [payload.size].pack('n') << payload ssl.write(message.join('')) ssl.close socket.close
  • 13. It’s time to Demo!
  • 14. 12 ★ • Miss Piggy • Catherine Miss Piggy • Mr. Kermit iPhone ★ Miss Piggy Cathy (Catherine) Miss Piggy Miss Piggy Cathy Kermit Miss Piggy Kermit iPhone Push Notification
  • 15. 13 References • Apple Push Notification Service Programming Guide http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/ RemoteNotificationsPG/Introduction/Introduction.html • How to build an Apple Push Notification provider server (tutorial) « Boxed Ice Blog http://blog.boxedice.com/2009/07/10/how-to-build-an-apple-push-notification-provider- server-tutorial/ • Ruby - pack http://www.ruby-lang.org/ja/man/html/ pack_A5C6A5F3A5D7A5ECA1BCA5C8CAB8BBFACEF3.html • SSL - 2008-01-03 - http://d.hatena.ne.jp/shinichiro_h/20080103#1199305204

×