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

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

on

  • 16,965 views

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

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

Statistics

Views

Total Views
16,965
Views on SlideShare
10,601
Embed Views
6,364

Actions

Likes
12
Downloads
110
Comments
0

7 Embeds 6,364

http://www.cocoalife.net 6327
http://webcache.googleusercontent.com 17
http://www.slideshare.net 13
http://s.deeeki.com 4
http://74.125.153.132 1
http://a0.twimg.com 1
http://localhost 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

  • How to build a server and a iPhone client application using the Apple Push Notification Service 2009/7/21 @ actindi Shu MASUDA
  • 2 Apple Push Notification Service (APNs) What is the Apple Push Notification Service? ‣ iPhone OS 3.0 ‣ 3 • Alert • Badge • Sound ‣
  • 3 Client Implementation Overview ★ APNs • UIApplication registerForRemoteNotificationTypes: • UIApplication application:didRegisterForRemoteNotificationsWithDeviceToken: Device Token ★ APNs • UIApplicationDelegate application:didReceiveRemoteNotification: • UIApplication Delegate applicationDidFinishLaunching:
  • 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-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
  • 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” } }
  • 9 Implementation in Ruby ★ Ruby • pack? unpack?? or ... ??? •
  • 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
  • It’s time to Demo!
  • 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
  • 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