Push

The content in this guide refers to the newly released version 3 of the library. You can still access the version 1.x guides here.

Version 1.x is now deprecated. We will continue to support 1.x through March 31, 2017 (End of Support - EOS). If you are currently using 1.x in your apps, you will need to upgrade your apps to 3.x before the EOS date. We have created a migration guide to help you.

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.

Production vs Development Push

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.

Because of this we need to provision the app differently for each mode.

Setup

Console Set Up

  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.

App Set Up

To configure push in your app, pass the configuration in usingKinvey.sharedClient.push.registerForPush(). This is usually done inside application:didFinishLaunchingWithOptions: after initializing Client.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
    //Your App Setup...

    Kinvey.sharedClient.initialize(appKey: "<#Your app key#>", appSecret: "<#Your app secret#>")

    Kinvey.sharedClient.push.registerForPush()

    return true
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
    //Your App Setup...

    Kinvey.sharedClient.initialize(appKey: "<#Your app key#>", appSecret: "<#Your app secret#>")

    Kinvey.sharedClient.push.registerForPush()

    return true
}

Receiving Push Notifications

In order to receive and handle push notifications in your application, you have to implement the application(didReceiveRemoteNotification:) method in your app delegate, as described below

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    // Push Notification handling code should be performed here
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    // Push Notification handling code should be performed here
}

For more details, please read Apple's documentation.

App Badge Management

You can have your app icon display a red badge with the number of unread push notifications. This is done through the Push object.

To set the badge to a particular number:

Kinvey.sharedClient.push.badgeNumber = 100 //sets to 100

To clear the badge:

Kinvey.sharedClient.push.resetBadgeNumber() //sets badgeNumber to 0
Got a question?