What is Push Notification ?

Push notification is a feature that allows an app to notify user of new messages or events, even when the user is not actively using your application. Like on Android devices, how a whatsapp message will make a sound and icon appear in the status bar.

What is Apple Push Notification service(APNs) ?

"Apple Push Notification service" is the service for implementing the push notification feature for IOS devices.

How it works ?

Each device establishes encrypted IP connection with the service and receives notifications over this persistent connection. If a notification for an application arrives when that application is not running, the device alerts the user that the application has data waiting for it.

How server originates push notifications for devices ?

Server connects with APNs through a persistent and secure channel while monitoring incoming data intended for their client applications. When new data for an application arrives, the server prepares and sends a notification through the channel to APNs, which pushes the notification to the target device.

How to implement it in Rails App ?

Multiple gems are available to implement Push Notifications in rails app example: [APNS][1] , [pushmeup(pushmeup)][2] , [apn_on_rails(apn_on_rails)][3] , [houston(houston)][4] etc.

We have used [APNS][5] gem in our app.

This need APNS certificate, [here are the steps to create APNS certificate(link)][6]

Then we have to convert cert.p12 file to cert.pem file and few configuration to specify .pem file path, APNS host and post.

APNS.host = 'gateway.push.apple.com'
APNS.pem  = '/path/to/pem/file'
APNS.port = 2195 

To send notification just write:

 APNS.send_notification(device_token, 'Hello iPhone!' )
  • device_token will be issued by Apple server and we have to save it in DB.

Similarly we can send multiple notification. [Click here for multiple notification][7] .

Thanks
[1]: https://github.com/jpoz/APNS#apns
[2]: https://github.com/NicosKaralis/pushmeup#pushmeup
[3]: https://github.com/PRX/apn_on_rails#apn-on-rails-apple-push-notifications-on-rails
[4]: https://github.com/nomad/Houston**
[5]: https://github.com/jpoz/APNS#apns
[6]: http://quickblox.com/developers/How_to_create_APNS_certificates
[7]: https://github.com/jpoz/APNS#example-multiple-notifications