Push

Push helps you reach out to your users in a timely fashion with important messages. You can use it to inform users about updates to some piece of data, about new services available nearby or that they are winners in a game. Using Custom server code you can set up triggers which send push notifications to a targeted set of people based on changes in the data you specify.

Kinvey brings Android Push Notifications to you through an integration with Google Cloud Messaging (GCM), and iOS Push Notifications through an integration with AWS SNS. While push notifications can only be configured to be used by either iOS or Android devices, our APIs provide support for registering/unregistering devices and associating them with Kinvey users.

Setup

Console Set Up

Android

  1. Navigate to the Google Mobile Services Add Service Wizard and follow the the instructions for creating a project, entering in your app info and adding Google Cloud Messaging to your app. Write down the Server API Key and Sender ID obtained.
  2. On the Kinvey's console navigate to Engagement and select Push.
  3. Select Configuration from the top.
  4. In the Android section, enter the API Key and Sender ID (also known as Project Number) obtained in step 1.
  5. Click Save Android

iOS

When using Apple Push Notification service (APNS) you will get two push certificates; one for development and one for production/ad-hoc. These certificates require push notifications to be sent to different servers depending on if your app is in development or production.

The production certificate is only usable if your app is in the App Store.

  1. Generate an Apple Push Certificate .p12 file for your app (instructions).
  2. After you export the .p12 file, on the Kinvey's console navigate to Engagement and select Push.
  3. Select Configuration from the top.
  4. In the iOS section drag your .p12 file generated in step 1 where it says DRAG FILES HERE.
  5. Click Save iOS
  6. When you are ready to deploy your app, use your production/ad-hoc certificate. Export the .p12 file, and upload that to our service. Then select production as the certificate type and click Save iOS. Deploying your application is a one-time action and cannot be undone.

Install Push Plugin

Please refer to the install guide to install the phonegap-push-plugin.

Push Notifications are intended for real devices. Push will fail on the iOS simulator. For Android, notifications can be made to work on the emulator as follows:

  1. Open the Android SDK Manager, and install the Google Cloud Messaging for Android Library under the Extras section.
  2. Open the AVD Manager and create a new Google API Emulator.
  3. After launching the emulator, go to Menu → Settings → Accounts & Sync. Add a Google account.
  4. Deploy your PhoneGap project to the emulator to test Push Notifications.

Register the device

The device needs to be registered to receive push notifications through Kinvey. There must be a logged-in user when registering. This user will be linked to the device, allowing you to send targeted push notifications.

To register the deivice, initialize the Push module:

var promise = Kinvey.Push.register({
  android: {
    senderID: '<Google Project ID>'
  },
  ios: {
    alert: true,
    badge: true,
    sound: true
  }
}).then(function(response) {
  // ...
}).catch(function(error) {
  // ...
});

Handling Push Notifications

You need to register a listener with the Push module to receive push notifications.

Kinvey.Push.onNotification(function(data) {
  ...
});

App Badge Management (iOS only)

You can have your app icon display a red badge with the number of unread push notifications. This is done by interacting with the PushPlugin directly:

// Set badge count to 100.
window.plugins.pushNotification.setApplicationIconBadgeNumber(function() {
    // Success.
}, function() {
    // Failure.
}, 100);

Disabling Push Notifications

The following code will disable push notifications for the active user:

var promise = Kinvey.Push.unregister().then(function(response) {
  // ...
}).catch(function(error) {
  // ...
});
Got a question?