Skip to content

Instantly share code, notes, and snippets.

@ys4kw
Last active December 22, 2015 10:39
Show Gist options
  • Save ys4kw/6460391 to your computer and use it in GitHub Desktop.
Save ys4kw/6460391 to your computer and use it in GitHub Desktop.
RubyでiOSのプッシュ通知
require 'apns'

# APNS.host = 'gateway.push.apple.com'
APNS.host = 'gateway.sandbox.push.apple.com' # sandbox url
APNS.pem = '/path/to/Certificates.pem'
APNS.pass = '<password>'
APNS.port = 2195

tokens = [
  '<device token>',
]

notifies = []
tokens.each do |token|
  notifies << APNS::Notification.new(token, alert: 'Hello', badge: 1, sound: 'default')
end
 
APNS.send_notifications(notifies)

gem install apns
(https://github.com/jpoz/APNS)

iOSから取得したPush notification用Tokenが必要

Certificates.pem作成

  1. Certificates.p12をkeychaninから取得
  2. openssl pkcs12 -in Certificates.p12 -out Certificates.pem -nodes -clcerts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment