Jonathan Clark
Jonathan Clark

Reputation: 20538

Using Parse push as stand alone service

I am building and iOS and Android app (two apps). I am looking for a replacement for Urban Airship which I do not longer trust. Mainly because I see no prices anywhere.

I want to use Parse Push as a stand alone product. Is this possible? I do not want to use any of the other Parse functionality.

Upvotes: 1

Views: 515

Answers (1)

Luca Iaco
Luca Iaco

Reputation: 3457

As explained in the Parse Push notification ( iOS like Android ) setup at https://parse.com/docs/push_guide#setup/iOS

Yes, you could. Of course you will need to include the parse sdk, since you'll need to register the devices through the Parse system. So:

Once you register the device for receiving push notification ( iOS example )

- (void)application:(UIApplication *)application
        didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    // Store the deviceToken in the current Installation and save it to Parse.
    PFInstallation *deviceInstallation = [PFInstallation currentInstallation];
    [deviceInstallation setDeviceTokenFromData:deviceToken];
    // this will be used later for sending push notifcations to this device       
    [deviceInstallation setChannels:@[deviceToken]]; 
    [deviceInstallation saveInBackground];
}

Sending Push notification through iOS

PFPush *pushObj = [[PFPush alloc] init];
NSString* destDeviceToken = @"<DESTIONATION DEVICE TOKEN>";

// Through channels, you can uniquely identify devices or group of them for multicast 
// push notification (imagine that more than one installation on your 
// Parse database keep the same channel name). 
// In this case we have set the channel name for each installation with the 
// only unique deviceToken
[pushObj setChannels:@[destDeviceToken]];

// Push structure message
[pushObj setData:@{@"My Message!!",@"alert"}];

// send push ( so, send to parse server that handle the push notification 
// request and deliver it for you)
[pushObj sendPushInBackground];

Sending Push notification through Android

String destDeviceToken = "<DESTIONATION DEVICE TOKEN>";
JSONObject data = new JSONObject("{\"alert\": \"My Message!!\"}");     
ParsePush *push = new ParsePush();
push.setChannel(destDeviceToken);
push.setData(data);
push.sendPushInBackground();

Sending Push notification through Javascript (Cloud Code) (it requires implementation on the Cloud code of Parse)

var destDeviceToken = '<DESTIONATION DEVICE TOKEN>';
Parse.Push.send({
  channels: [ destDeviceToken ],
  data: {
    alert: "My Message!!"
  }
}, {
  success: function() {
    // Push was successful
  },
  error: function(error) {
    // Handle error
  }
});

Sending Push notification through REST call (it allow you to perform a sending push notification without working on Parse anymore, so from any other platform that support a REST call)

curl -X POST \
  -H "X-Parse-Application-Id: <YOUR PARSE APP ID>" \
  -H "X-Parse-REST-API-Key: <YOUR REST API KEY>" \
  -H "Content-Type: application/json" \
  -d '{
        "channels": [
          "<DESTIONATION DEVICE TOKEN>"
        ],
        "data": {
          "alert": "My Message!!",
        }
      }' \
  https://api.parse.com/1/push

In this way you don't need any additional implementation, like registering users or something like that.

Hope it helps!

Upvotes: 1

Related Questions