Send Push notifications to Android/iOS devices using Parse
This tutorial will help you to send Push notifications to Android and iOS devices from Ruby on Rails application using Parse
Parse
What is Parse?
Parse can be used to increase user engagement with targeted push notifications to mobile devices having Android / iOS running. Push notifications can be sent across devices and platforms with ease. Head over to Parse to get started with Parse
Setting up Android Application
Follow the Android Push Notifications doc to set up your Android Application to use Parse for receiving Push Notifications
Setting up iOS Application
Follow the iOS Push Notifications doc to set up your iOS Application to use Parse for receiving Push Notifications
Rubygem - parse-ruby-client
Parse Ruby Client is Ruby Gem that can be used to Send Push notifications to Android/iOS devices from Ruby
Github: parse-ruby-client
Setup Steps:
1. Obtaining Application ID and API Key
To use Parse with Ruby, you will need application_id and api_key.
-
appliaction_id
This uniquely identifies your subscription and corresponding devices/configuration under your Application
-
api_key
This is the REST API key as shown in the image given below If you are Registered with Parse, you can find this under Parse App Keys section as given in the Screenshot given above
2. Install
parse-ruby-client can be installed by
If you are building Ruby on Rails application, then you need to add gem to the Gemfile as,
This will install and configure latest Stable version with your Rails Application
3. Initialize Parse
Initialize Parse by passing your applicationid and apikey as given below -
application_id: is the application_id as given above
api_key: is the REST api key as given above
quiet: Logging Parameter if set equal to true - you will get Parse process logs
4. Send Push Notification
Channels
We can send notifications to Channels subscribed from Android/iOS devices using the code -
data - It is a hash that gets delivered to android/iOS device
Organization - This is the channel to which your application should be subscribed of push.type - This sets device type as android / ios as per the need
Individual Target (Advanced Targeting)
We can send notifications to Individuals subscribed from Android/iOS devices using the code -
5. Ruby Implementation
which can be used as a Service or Library in your Ruby on Rails Applications
Above class can be used to Send Notifications to Individual users as well as Channel as given below
Send to Individual -
Send to Channel/Organization -
By using above two types of Push Notification sends you can send push notifications at any time to any device
Handling Response
After push.save, Parse will return response something like -
This indicates that your Push Notification is successfully enqueued for sending with Parse service.
Sometimes Push can also send protocol error if it finds some error in your request and returns Exception
Tracking Push Notifications
You can check the status of your Push notifications from Parse dashboard itself. Just visit the Push tab from your Parse account - https://www.parse.com/apps/organization-name/push_notifications
Subscribe to Ruby in Rails
Get the latest posts delivered right to your inbox