user3055120
user3055120

Reputation: 65

Pushing notifications from Ruby On Rails to Android and IOS users using Parse

I'm building an application using Ruby On Rails. the app is supposed to push notifications to android and IOS user using Parse RESTfull api. i have tried to use parse-ruby-client but the documentation is poor and a don't get how it really works. i mean how to send a notification a specific user.

Upvotes: 0

Views: 1259

Answers (1)

jimrice
jimrice

Reputation: 452

In order to send a notification to a specific user you first need to have channels for each user setup or query a specific installation. With parse and the rest api the easiest way I have found to send a notification to an individual user is to setup each user as a channel. When the user initially sets up the app on their device, I take either their username or email and use that as their channel. Then when I want to send a notification to a specific user I send to that channel.

In ruby to send to a channel you would use the following substituting your channel in place of Giants

data = { :alert => "This is a notification from Parse" }
push = Parse::Push.new(data, "Giants")
push.type = "ios"
push.save

For advanced targeting, for example, if you want to query a class and find iOS users with injury reports set to true you can use the following:

data = { :alert => "This is a notification from Parse" }
push = Parse::Push.new(data)
push.type = "ios"
query = Parse::Query.new(Parse::Protocol::CLASS_INSTALLATION).eq('injuryReports', true)
push.where = query.where
push.save

The push.type refers to the system type- iOS (ios), android (android), windows user (winrt or winphone).

Upvotes: 1

Related Questions