Baylor Mitchell
Baylor Mitchell

Reputation: 1059

How to configure Push Notifications on Parse Server?

I have deployed a Parse Server on Heroku and mongoDb using a modified fork of the parse-server-example on GitHub. I have looked at the wiki here on how to send push notifications on parse server: https://github.com/ParsePlatform/parse-server/wiki/Push but I am looking for a more in-depth response. My CLOUD CODE (cloud/main.js) to send a scheduled push notification (which functioned properly on the hosted version of Parse) is

    Parse.Cloud.define('sendPush', function(request, response) {


    var userQuery = new Parse.Query(Parse.User);
    userQuery.equalTo('username', request.params.targetUsername);


    var pushQuery = new Parse.Query(Parse.Installation);
    pushQuery.matchesQuery('user', userQuery);


   Parse.Push.send({
   where: pushQuery,
     data: {
        alert: 'You have a new message from ' + request.params.fromUsername + '!'
      }, 
      push_time: request.params.date
    }, {
      success: function() {
        // Push was successful
        response.success('push successful')
      },
      error: function(error) {
        // Handle error
        response.error('push failed')
      }
   });

    });

I am working strictly with iOS and I am looking to have this code function again on my Parse Server. The wiki guide says I need to configure the Parse server, which I am not sure how to do or where to do it. Any help is appreciated. Thanks

Upvotes: 1

Views: 6701

Answers (4)

lastoneisbearfood
lastoneisbearfood

Reputation: 4125

Depends on how you start your parse-server. If you start it directly on the command line, you can do:

parse-server myConfig.json

The server entire configuration goes into this myConfig.json file, for push and for other aspects of your server. Here is an example content of myConfig.json

{
   "appId": "APP-ID",
   "masterKey": "MMASTER-KEY",
   "cloud": "relative-path-to-directory-that-contains/main.js",
   "push": {
      "ios":{
         "pfx": "relative-path-to-apple-push-cert.p12",
         "bundleId": "com.company.appname",
         "production": false
      },
      "android":{
         "senderId": "your-gcm-sender-id",
         "apiKey": "your-api-key"
      }
   }
}

If you start your parse-server from express or from some node script, the answer is similar to others have said, except that the paths have to be absolute paths:

var server = ParseServer({
   "appId": "APP-ID",
   "masterKey": "MMASTER-KEY",
   "cloud": "absolute-path-to-directory-that-contains/main.js",
   "push": {
      "ios":{
         "pfx": "absolute-path-to-apple-push-cert.p12",
         "bundleId": "com.company.appname",
         "production": false
      },
      "android":{
         "senderId": "your-gcm-sender-id",
         "apiKey": "your-api-key"
      }
   }
})

It's been 3 months since you asked this question so you probably have gotten over the initial confusion of setting up a parse-server. If you still have questions, it may help to go through the exercise of setting up parse-server on your local machine so you know exactly where's where and what's what.

Here is a guide to setup parse-server for local development.

Upvotes: 2

user6427611
user6427611

Reputation:

Its easy you just need to put your push notification keys in the parse config. In your index.js file just add push object to new ParseServer initialization like this:

var server = new ParseServer({
    push: {
      android: {
        senderId: 'your send id',
        apiKey: 'your app key'
      },
      ios: {
        pfx: 'path to pfx local',
        bundleId: '',
        production: false
      }
    },
    databaseURI: 'your database uri',
    appId: 'your app key',
    masterKey: 'master key',
  });

Upvotes: 2

anti_gone
anti_gone

Reputation: 973

From the parse-server wiki:

 var server = new ParseServer({
    databaseURI: '...',
    cloud: '...',
    appId: '...',
    masterKey: '...',
    push: {
      android: {
        senderId: '...',
        apiKey: '...'
      },
      ios: {
        pfx: '/file/path/to/XXX.p12',
        bundleId: '',
        production: false
      }
    }
  });

So you just put everything in there inside your main.js.

You can also find a really comprehensive guide for setting up push notifications on parse-server here:

https://guides.codepath.com/android/Configuring-a-Parse-Server

Upvotes: 2

ribads
ribads

Reputation: 393

You need to configure your parse-server with the necessary key for push notification

Visit https://github.com/ParsePlatform/parse-server/wiki/Push to learn how to achieve this.

Upvotes: 0

Related Questions