undefined

Push Notifications

Push Notifications provide a way to deliver some information to user while he is not using your app actively. The following use cases can be covered additionally with push notifications:

  • send a chat message and recipient is offline (a push notification will be sent automatically)
  • make a video call with offline opponents (need to send a push notification manually)
  • request to add a user to contact list (need to send a push notification manually)

Configuration

In order to start work with push notifications you need to configure it.

For iOS application that uses Apple Push Notifications you must have APNS certificate uploaded via the ConnectyCube Dashboard Console panel.

For Android application that uses Firebase Cloud Messaging (FCM) you need to obtain API Key and set it on ConnectyCube Dashboard Console panel.

Subscribe

In order to start receiving push notifications you need to subscribe your current device as follows:

var params = {
    notification_channels: 'apns', // or 'gcm' for Android
    device: {
        platform: 'ios',
        udid: '2b6f0cc904d137be2e1730235f5664094b831186'
    },
    push_token: {
        environment: 'development',
        client_identification_sequence: '2b6f0cc9...4b831186'
    }
};

ConnectyCube.pushnotifications.subscriptions.create(params, function(error, result){

});

Send push notifications

You can manually initiate a push notification to user/users on any event in your application. To do so you need to form a push notification parameters (payload) and set the push recipients:

var payload = JSON.stringify({
  message: 'New market products are available',
  ios_badge: 5,
});

var pushParameters = {
  notification_type: 'push',
  user: {ids: [21, 12]}, // recipients.
  environment: 'development', // environment, can be 'production'.
  message: ConnectyCube.pushnotifications.base64Encode(payload)
};

ConnectyCube.pushnotifications.events.create(pushParameters, function(error, result) {

});

Receive push notifications

The flow how you receive push notifications depends on what platform you use: NativeScript, ReactNative or something else. Please refer to the push notifications documentation of these platforms.

Unsubscribe

In order to unsubscribe you need to list your current subscriptions and then choose those to be deleted:

ConnectyCube.pushnotifications.subscriptions.list(function(error, subscriptions){
  if (!error) {
    var subscriptionId = subscriptions[0].subscription.id;

    ConnectyCube.pushnotifications.subscriptions.delete(subscriptionId, function(error){

    });
  }
});