顯示具有 APNS 標籤的文章。 顯示所有文章
顯示具有 APNS 標籤的文章。 顯示所有文章

2012年8月17日 星期五

APNS 架設

APNS 憑證流程 官方最新必看

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

grocer - 另一個 APNS 選擇

https://github.com/highgroove/grocer

好處:支援中文,支援度、擴充性更高

C:\Users\APNS>gem install grocer
Fetching: grocer-0.1.0.gem (100%)
Successfully installed grocer-0.1.0
1 gem installed
Installing ri documentation for grocer-0.1.0...
Installing RDoc documentation for grocer-0.1.0...



$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)

Gem for APNS

PS: 這個版本 目前送中文會有問題

A gem for the Apple Push Notification Service


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...


push.rb
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')

2012年8月10日 星期五

Sinatra

on Windows

首先需要 安裝 Ruby
選擇安裝 Ruby Installer 一鍵安裝 免設定
在這邊安裝的版本是 Ruby 1.9.3-p194

打開 Command Line
確認一下環境&版本

C:\Users\user>ruby -v

ruby 1.9.3p194 (2012-04-20) [i386-mingw32]

C:\Users\user>gem -v

1.8.23


安裝 Sinatra

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


就跟他的網頁一樣

簡潔


製作 APNS 憑證
How to build an Apple Push Notification provider server (tutorial)

gem for APNS
https://github.com/jpoz/APNS