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.
We have used APNS gem for our app.
This need APNS certificate, here are the steps to create APNS certificate
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