Sunday 8 October 2017

Pushmeup gem for IOS push notification rails5

This gem is a wrapper to send push notifications to devices. Currently it only sends to Android or iOS devices, but more platforms will be added soon. With APNS (Apple Push Notifications Service) you can send push notifications to Apple devices. With GCM (Google Cloud Messaging) you can send push notifications to Android devices.
Im not going to cover the Android part.
add it to Gemfile
gem ‘pushmeup’
APNS (Apple iOS)
Configure (mobile side)
In Keychain access export your certificate and your private key as a p12.
![Keychain Access](
https://raw.github.com/NicosKaralis/pushmeup/master/KeychainAccess.jpg)
Run the following command to convert the p12 to a pem file
$ openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts
Configure (server(rails) side)
a. After you have created your pem file.
b.Set the host, port and certificate file location on the APNS class. You just need to set this once:
create a file called push_me_up.rb and env.yml(files names are not mandatory to be same name and check if you already have the file for environment variable)

push_me_up.rb

 APNS.host = ENV[“APNS_HOST”]
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 = Rails.root/ENV[“APNS_PEM”]
 # this is also the default. Shouldn’t ever have to set this, but just in case Apple goes crazy, you can.
APNS.pass = ENV[“APNS_PASS”]

 env.yml
APNS_HOST: gateway.push.apple.com
 # gateway.sandbox.push.apple.com is default and only for development
 # gateway.push.apple.com is only for production
APNS_PEM: pem_file.pem

 APNS_PASS: password
 # Just in case your pem need a password
Now, configurations are over and we will start using it
Usage
Sending a single notification(inside controller or service or worker any where*):
device_token = ‘123abc456def’
 APNS.send_notification(device_token, ‘Hello iPhone!’ )
 APNS.send_notification(device_token, :alert => ‘Hello iPhone!’, :badge => 1, :sound => ‘default’)
Sending multiple notifications and other options please refer the link (pushmeup)

No comments:

Post a Comment