Cordova > SDK integration

Push setup

Enabling Batch push

Activate Batch Push by calling batch.push.setup(), right before setting the Batch API Key (either dev or live). If you target Android, please call batch.push.setGCMSenderID() before starting the push module.

On iOS, you need to call batch.push.registerForRemoteNotifications() every time your application is started. You can, however, delay the very first call to another place in your app, so that the notification request popup is shown at a later date.

var app = {
    onDeviceReady: function() {
        batch.setConfig({"androidAPIKey":"<YOUR ANDROID APIKEY>",
            "iOSAPIKey":"<YOUR IOS APIKEY>"});
        batch.push.setGCMSenderID("<YOUR GCM SENDER ID>").setup();

Many Batch calls can be chained, as shown in that example.

Follow the Customizing Batch notifications guide to display your notification icon correctly on Android and manage your iOS/Android notification display.

Your first notification

1. Obtaining your device token

You can find your device's token using the debug tool or locating the token Batch posts to the logs. Be sure to launch the app on your device linked to your computer.

Batch's logs are displayed in the logcat/Xcode console, but they are also forwarded.

Recent Android versions should show logs that happened before you opened Chrome's debugger, but older android versions and iOS do not, so you might miss the push token here. In that case, you need to take a look in the device logs (Window -> Devices for Xcode, adb logcat for android).

The line you are looking for within the logcat/console is:

Batch.Push: Registration id: X

//Where X represents the Batch Push token for your device.
[Batch] - Push token (Production): X
[Batch] - Push token (Development): X

//Where X represents the Batch Push token for your device.
//The token shown in the console will be Production or Development based on 
//your Provisioning Profile. Be sure to note which token you are working with. 
//If you are having troubles finding the entry, searching for Batch will 
//find the correct entries.

2. Sending a test push

Go to ⚙ Settings → Push settings, paste your device's token and click on Save. On iOS, make sure you chose the right environment.

Then, all you have to do is to click on the "Send" button. If you sucessfuly set up the SDK, you will receive a notification on your device.

Test push iOS

If you're having trouble sending test notifications, you can check our troubleshooting documentation:
- iOS
- Android

What's next

Congratulations on finishing the integration of Batch Push!

Here are a couple of extra steps you can take before releasing your app:

  • Live API key: Ensure you don't use Batch's DEV API key in the build you will upload to the AppStore / Play Store.
  • Small icon / Accent color: On Android, make sure the small icon you are using is opaque white. We also recommend you use an accent color.
  • Custom user identifier: Add support for custom user identifiers if you are planning to use the Transactional or the Custom Data APIs.
  • Token import: Import your existing tokens if you're coming from another push provider.