Set Up Push Notifications

Set Up Push Notifications

The Kahuna Plugin for Cordova/PhoneGap enables you to send targeted push notifications for both iOS and Android platforms. See Before You Begin for information about push notification with Kahuna.

Set Up Push Notifications


To set up push notifications, you need to:

Generate a Certificate Signing Request (CSR)

Generate your (CSR) to be able to create a Push SSL Certificate for your app.

Note: If you already have a CSR for your app, skip this procedure.

  1. From the Utilities folder in Applications on your Mac, open the Keychain Access application.

  2. From the Keychain Access menu (in the Apple toolbar in the top left of your screen), select Certificate Assistant, then select Request a Certificate from a Certificate Authority. The Certificate Assistant opens.
  3. In the User Email Address field, provide your email address.
  4. In the Common Name field, provide a name for your application (for example, MyCoolApp).
  5. Check the Saved to disk option, then click Continue to save your CSR.

Enable Push Notifications

Note: If your app already supports push, skip this procedure.

  1. Ensure your application is properly provisioned in the iOS Provisioning Portal.

    Note: Push does not support the wildcard App ID. Your application must have a valid Bundle Identifier (including Development builds).

  2. The App IDs area of the iOS Provisioning Portal provides a description for your application as well as little green or gray indicators for Push Notification; both Development and Distribution. Click Edit to continue. The Push Notifications dialog opens.

    Note: To configure your app, you need to be the Team Agent.

  3. Enable the Apple Push Notification service for Development and Distribution. Kahuna recommends you enable the Apple Push Notification service for both so that you can test before deploying to production.
  4. Click on the Create Certificate button and point to the CSR you created above.
  5. Follow the steps to specify your CSR.
  6. After you have generated your Push SSL Certificate, you are directed back to the Enable Push Notification dialog where the status indicator is green and Enabled.
  7. Click Download to download your Push SSL Certificate.
  8. Open the downloaded certificate. The Keychain Access application opens.
  9. Under My Certificates, select the certificate that was just added, then select Export Items from the File menu.
  10. In the Save dialog, provide a name for the certificate and click Save.

    Note: Make sure you save the certificate file in Personal Information Exchange (.p12) format.

Upload the Push Certificate to Kahuna

  1. In the Kahuna application, click on the top bar, then click Settings to open the Settings page.
  2. Scroll down to the Push Authorization section.
  3. In the Apple Push Certificates area, drag and drop the certificate you downloaded from the iOS Provisioning Portal.

Support Push in Your Application

To support push notifications in your application, incorporate the following lines into your application delegate.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    // Call other Kahuna integration APIs here, such as launchWithKey, loginWithCredentials
    [Kahuna enablePushNotifications];

    // If you are implementing didReceiveRemoteNotification:fetchCompletionHandler, call 
    // [Kahuna handleNotification] in that method
    // Otherwise, call handleNotification as shown below
    [Kahuna handleNotification:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]

    // Add your app initialization code here
    return YES;

- (void) application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings 
    [[UIApplication sharedApplication] registerForRemoteNotifications];

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    [Kahuna setDeviceToken:deviceToken];

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    [Kahuna handleNotificationRegistrationFailure:error];

Regular Push Notifications

If you use standard push notifications, add this method to your application delegate:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    [Kahuna handleNotification:userInfo withApplicationState:application.applicationState];

Actionable Push Notifications

If you use iOS Push Categories in your app, add this method to your application delegate:

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)actionIdentifier
                                                      forRemoteNotification:(NSDictionary *)userInfo
                                                          completionHandler:(void (^)())completionHandler
    [Kahuna handleNotification:userInfo withActionIdentifier:actionIdentifier

    // Call the completion handler here

Note: Firebase support for Cordova/PhoneGap coming soon!

  1. From the Google API Console, obtain the Google API project number for your app and the Server API key. Kahuna needs the key to push on your behalf.

    If you have not created a Google API project for your app, you need to create a project, enable Google Cloud Messaging (GCM) for Android service, and generate a Server API key.

  2. Add the Server API key to your account.

    1. In the Kahuna application, click on the top bar, then click Settings to open the Settings page.
    2. Scroll down to the Push Authorization section.
    3. In the Android GCM/FCM Server Key field, enter the GCM Server key.
    4. Click Test and Save the GCM/FCM Server key.
  3. Update your manifest for Push.

    Push requires several receivers, permissions and a service to function properly. The following is an example of a sample manifest file which has push enabled. This example manifest serves a guide. You must update or change the tags in the Modification and Required areas.

    Note: Improper permission settings or missing receivers in your manifest prevent your application from obtaining a device token to which Kahuna can push.

    <?xml version="1.0" encoding="utf-8"?> 
    <!-- MODIFICATION: Change package="com.kahuna.sample" to your app package name --> 
    <manifest xmlns:android="" 
        android:versionName="1.0" > 
        <!-- Push currently only supports Android versions 2.2 and above --> 
            android:targetSdkVersion="17" /> 
        <!-- REQUIRED: Kahuna's push requires the following permissions --> 
        <!-- MODIFICATION: Replace "com.kahuna.sample" with your app package name --> 
            android:protectionLevel="signature" /> 
        <uses-permission android:name="com.kahuna.sample.permission.C2D_MESSAGE" /> 
        <uses-permission android:name="android.permission.INTERNET" /> 
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
        <!-- App receives GCM messages. --> 
        <uses-permission android:name="" /> 
        <!-- GCM requires a Google account. --> 
        <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
        <!-- Keeps the processor from sleeping when a message is received. --> 
        <uses-permission android:name="android.permission.WAKE_LOCK" /> 
        <!-- END of permissions required for Kahuna Push --> 
        <!-- MODIFICATION: Replace "com.kahuna.sample.KASampleApplication" with your app 
            package name --> 
                android:label="@string/app_name" > 
                    <action android:name="android.intent.action.MAIN" /> 
                    <category android:name="android.intent.category.LAUNCHER" /> 
            <!-- REQUIRED: Kahuna's push requires the receivers and service --> 
            <receiver android:name="com.kahuna.sdk.KahunaCoreReceiver" /> 
                android:permission="" > 
                    <action android:name="" /> 
                    <action android:name="" /> 
                    <!-- MODIFICATION: Replace "com.kahuna.sample" with your package --> 
                    <category android:name="com.kahuna.sample" /> 
            <service android:name="com.kahuna.sdk.KahunaPushService" /> 
            <!-- END of Kahuna's push requirements --> 
  4. To support Push in your application, incorporate the following line into your Main Application class and replace YOUR_SENDER_ID with your API project number from step 1 above.

    public class SampleApplication extends Application {
        public void onCreate() {
            Kahuna.getInstance().onAppCreate(this, "KAHUNA_SECRET_KEY", "YOUR_SENDER_ID");
            // Your Code Here

    Push is controlled entirely by the application. Kahuna recommends that your application expose a setting to the user to enable and disable Push depending on their preferences. Push is enabled by default and you can disable it with the following after calling onAppCreate().


    To obtain the push token for the device, use the following method call.


    You can call this method as soon as your Main Activity starts. You need to call it every time your app launches, because the push token can change over time. For example, the token has the value null if you disable push.

    In the Android OS, each app controls push. You can design your Android app to allow each user the choice of receiving or blocking push notifications, independent of other apps on the device. The Kahuna SDK provides several ways to query, enable or disable push notifications, which allows you to provide a push toggle control in your app. By default, the SDK enables push notifications.

    The following API call returns the state of push enabling.


    The following API calls disable and enable push notifications in the SDK.


    After you turn off push notifications, you need to enable them again before the device receives them. The SDK automatically stores the state of push enabling so that you don't have to save it when your app goes into the background or restore it when your app comes back to the foreground.

    Note: Because Android expects each app to handle push notifications, the Kahuna APIs only control push notifications sent by Kahuna. Your app must handle push enabling separately for each third-party system that sends push notifications.

Optional - Set Up Push Callback

  1. Integrate the following call anywhere in your app to support Push in your iOS application.

    Note: Push must be tested on an actual device, it will not work in the iOS simulator.

    onDeviceReady: function() {
  2. Add the kahunaCallback function outside the app object of your index.js file.

    function kahunaCallback (payload) {
        var type = payload['type']; // For push messages this value will be pushMessage
        var message = payload['message']; // The push message
        var extras = payload['extras']; //  parameters associated with the Push
        var applicationState = payload['applicationState']; // iOS Only. State of the application. 0:Active, 1:InActive, 2:Background
        if (type == 'pushMessage') {
            alert ('push message ' + message + ' received');
  3. Register the kahunaCallback callback function inside onDeviceReady as shown below.


Now follow the steps in Set Up In-App Messaging.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request