Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
How to build a server and a iPhone client
   application using the Apple Push
         Notification Service
            200...
2
Apple Push Notification Service (APNs)
What is the Apple Push Notification Service?



 ‣ iPhone OS 3.0
 ‣                ...
3
Client Implementation Overview

 ★ APNs
  •   UIApplication   registerForRemoteNotificationTypes:



  •   UIApplication ...
4
Client Implementation




 •           Xcode
5
Server Implementation Overview


 1. App ID


 2.

 3. Interface APNS


 4.          Ruby
6
Generating App ID




                       Bundle
     Identifier   ”*”
6
Generating App ID




     Enable for Apple Push Notification service
6
Generating App ID




     Enable for Apple Push Notification service
7
Generating Key
 1.   p12     pem

      •    openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in
           apns-...
8
Creating the Push Notification Interface

 • Binary format of the push notification interface



 •              (payload)...
9
Implementation in Ruby
 ★ Ruby

  •   pack? unpack?? or ... ???

  •
10
Implementation in Ruby
#! /usr/bin/env ruby
# -*- encoding: utf-8 -*-

require 'socket'
require 'openssl'

socket = TCP...
It’s time to Demo!
12


★
•   Miss Piggy

•   Catherine       Miss Piggy

•   Mr. Kermit      iPhone


★
Miss Piggy                 Cathy (Ca...
13
References


 •   Apple Push Notification Service Programming Guide
     http://developer.apple.com/iphone/library/docum...
Upcoming SlideShare
Loading in …5
×

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

14,109 views

Published on

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

Published in: Technology
  • Be the first to comment

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

  1. 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. 2 Apple Push Notification Service (APNs) What is the Apple Push Notification Service? ‣ iPhone OS 3.0 ‣ 3 • Alert • Badge • Sound ‣
  3. 3. 3 Client Implementation Overview ★ APNs • UIApplication registerForRemoteNotificationTypes: • UIApplication application:didRegisterForRemoteNotificationsWithDeviceToken: Device Token ★ APNs • UIApplicationDelegate application:didReceiveRemoteNotification: • UIApplication Delegate applicationDidFinishLaunching:
  4. 4. 4 Client Implementation • Xcode
  5. 5. 5 Server Implementation Overview 1. App ID 2. 3. Interface APNS 4. Ruby
  6. 6. 6 Generating App ID Bundle Identifier ”*”
  7. 7. 6 Generating App ID Enable for Apple Push Notification service
  8. 8. 6 Generating App ID Enable for Apple Push Notification service
  9. 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. 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. 11. 9 Implementation in Ruby ★ Ruby • pack? unpack?? or ... ??? •
  12. 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. 13. It’s time to Demo!
  14. 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. 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

×