资源说明:A Ruby-based server and toolkit for sending iPhone push notifications
h1. Apple Push Notification Server Toolkit * http://github.com/bpoweski/apnserver h2. Description apnserver is a server and set of command line programs to send push notifications to the iPhone. Apple recommends to maintain an open connection to the push notification service and refrain from opening up and tearing down SSL connections repeated. To solve this problem an intermediate network server is introduced that queues are requests to the APN service and sends them via a persistent connection. h2. Remaining Tasks * Implement feedback service mechanism * Implement robust notification sending in reactor periodic scheduler h2. Issues Fixed * second attempt at retry logic, SSL Errors close down sockets now * apnsend --badge option correctly sends integer number rather than string of number for aps json payload * connections are properly closed in Notification#push method now * removed json gem in favor of ActiveSupport * Rails 3.x support * drop the erroneous puts statements in favor a configurable logger * moved to Rspec h2. APN Server Daemonh2. APN Server Client With the APN server client script you can send push notifications directly to Apple's APN server over an SSL connection or to the above daemon using a plain socket. To send a notification to Apple's APN server using SSL the *--pem* option must be used.Usage: apnserverd [options] --pem /path/to/pem --bind-address bind address (defaults to 0.0.0.0) bind address of the server daemon --proxy-port port the port that the daemon will listen on (defaults to 22195) --server server APN Server (defaults to gateway.push.apple.com) --port port of the APN Server APN server port (defaults to 2195) --pem pem file path The PEM encoded private key and certificate. To export a PEM ecoded file execute # openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts --pem-passphrase passphrase The PEM passphrase to decode key. --help usage message --daemon Runs process as daemon, not available on WindowsTo send a base64 encoded push notification via the command line execute the following:Usage: apnsend [switches] (--b64-token | --hex-token)--server the apn server defaults to a locally running apnserverd --port <2195> the port of the apn server --pem the path to the pem file, if a pem is supplied the server defaults to gateway.push.apple.com:2195 --pem-passphrase the pem passphrase --alert the message to send" --sound the sound to play, defaults to 'default' --badge the badge number --custom a custom json string to be added to the main object --b64-token a base 64 encoded device token --hex-token a hex encoded device token --help this message h2. Sending Notifications from Ruby To configure the client to send to the local apnserverd process configure the ApnServer client with the following.$ apnsend --server gateway.push.apple.com --port 2195 --pem key.pem \ --b64-token j92f12jh8lqcAwcOVeSIrsBxibaJ0xyCi8/AkmzNlk8= --sound default \ --alert HelloTo configure the client to send directly to Apple's push notification server, bypassing the apnserverd process configure the following.# configured for a using the apnserverd proxy ApnServer::Config.host = 'localhost' ApnServer::Config.port = 22195 ApnServer::Config.logger = Rails.loggerFinally within we can send a push notification using the following codeApnServer::Config.pem = '/path/to/pem' ApnServer::Config.host = 'gateway.push.apple.com' ApnServer::Config.port = 2195h2. Installation Apnserver is hosted on "rubygems":https://rubygems.org/gems/apnservernotification = ApnServer::Notification.new notification.device_token = Base64.decode64(apns_token) # if base64 encoded notification.alert = message notification.badge = 1 notification.sound = 'default' notification.pushAdding apnserver to your Rails application$ gem install apnserverh2. License (The MIT License) Copyright (c) 2011 Ben Poweski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.gem 'apnserver', '>= 0.2.0
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。
English
