Push setup

Setting up the Push

First of all, open your project in Xcode by clicking on it in the sidebar, then click on the Signing & Capabilities tab. If Push Notifications isn't already there, click on + Capability and pick Push Notifications. If there is a Fix button shown, press it.

Xcode Capabilities

Then, you need to add a few lines to your app delegate in order to receive push notifications.

To ask for the permission to display notifications and register the current device for push, call the method [BatchPush requestNotificationAuthorization] in your application delegate or wherever it is appropriate.

  • Objective-C
  • Swift
@import Batch;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    // Start Batch.
    [Batch startWithAPIKey:@"YOUR_API_KEY"]; 
    // Ask for the permission to display notifications
    // The push token will automatically be fetched by the SDK
    [BatchPush requestNotificationAuthorization];

    // Alternatively, you can call requestNotificationAuthorization later
    // But, you should always refresh your token on each application start
    // This will make sure that even if your user's token changes, you still get notifications
    // [BatchPush refreshToken];

    // Sets Batch as your UNUserNotificationCenterDelegate.
    // This will disable the legacy callbacks on your app delegate (didReceiveRemoteNotification, ...).
    // If you rely on those, do not add this line and please consider migrating to the UserNotification framework.
    // If you already have a UNUserNotificationCenterDelegate implementation, do not add this line.
    // Instead, add Batch's callbacks in your implementation. See 'Advanced > Intercepting notifications', 
    [BatchUNUserNotificationCenterDelegate registerAsDelegate];

    return YES;

Note: If you already implement a UNUserNotificationCenterDelegate class, please read the intercepting notifications documentation to properly integrate Batch into it.

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 Xcode console:

[Batch] - Push token (Apple Push Production): <push token>

Based on your Provisioning Profile, the token shown in the console will be Development ("Sandbox/Development") or Production ("Production").

2. Sending a test push

Go to ⚙ Settings → Push settings, paste your device's token, choose the right environment and click on Save.

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.

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: