How to build an Apple Push Notification provider server 舊的方式(可參考)
Installing the SSL Certificate and Key on the Server
仔細看 步驟二、步驟三 即可匯出 p12
執行底下指令 就可將 p12 轉 pem
openssl pkcs12 -in CertificateName.p12 -out CertificateName.pem -nodes
openssl pkcs12 -in CertificateName.p12 -out CertificateName.pem -nodes
$pusher = Grocer.pusher(
certificate: 'C:\Users\Ruby\APNS\push_test.pem',
gateway: "gateway.sandbox.push.apple.com" # optional; defaults to gateway.push.apple.com.
)
n = Grocer::Notification.new(
device_token: '12345',
alert: "Hello iPhone!",
badge: 1)
$pusher.push(n)
C:\Users\user\>gem install apns Fetching: apns-0.9.0.gem (100%) Successfully installed apns-0.9.0 1 gem installed Installing ri documentation for apns-0.9.0... Installing RDoc documentation for apns-0.9.0...
require 'rubygems' require 'apns' # https://github.com/jpoz/APNS # APNS.host = 'gateway.push.apple.com' # gateway.sandbox.push.apple.com is default # APNS.pem = '/path/to/pem/file' # this is the file you just created # APNS.port = 2195 # this is also the default. Shouldn't ever have to set this, but just in case Apple goes crazy, you can. APNS.pem = 'C:\Users\APNS\apns.pem' device_token = '123abc456def' APNS.send_notification(device_token, 'Hello iPhone!' ) APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')
C:\Users\user>ruby -v ruby 1.9.3p194 (2012-04-20) [i386-mingw32] C:\Users\user>gem -v 1.8.23
C:\Users\user>gem install sinatra Fetching: rack-1.4.1.gem (100%) Fetching: rack-protection-1.2.0.gem (100%) Fetching: tilt-1.3.3.gem (100%) Fetching: sinatra-1.3.2.gem (100%) Successfully installed rack-1.4.1 Successfully installed rack-protection-1.2.0 Successfully installed tilt-1.3.3 Successfully installed sinatra-1.3.2 4 gems installed Installing ri documentation for rack-1.4.1... Installing ri documentation for rack-protection-1.2.0... Installing ri documentation for tilt-1.3.3... Installing ri documentation for sinatra-1.3.2... Installing RDoc documentation for rack-1.4.1... Installing RDoc documentation for rack-protection-1.2.0... Installing RDoc documentation for tilt-1.3.3... Installing RDoc documentation for sinatra-1.3.2...
# myapp.rb require 'sinatra' get '/' do 'Hello world!' end
C:\Users\user>ruby myapp.rb [2012-08-10 15:36:21] INFO WEBrick 1.3.1 [2012-08-10 15:36:21] INFO ruby 1.9.3 (2012-04-20) [i386-mingw32] == Sinatra/1.3.2 has taken the stage on 4567 for development with backup from WEBrick [2012-08-10 15:36:21] INFO WEBrick::HTTPServer#start: pid=140360 port=4567