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] , [pushmeup(pushmeup)] , [apn_on_rails(apn_on_rails)] , [houston(houston)] etc.
We have used [APNS] gem in our app.
This need APNS certificate, [here are the steps to create APNS certificate(link)]
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] .
Subscribe to Engineering At Kiprosh
Get the latest posts delivered right to your inbox