iOS > SDK integration

Push setup

Setting up the Push

Since you've generated a new provisioning profile, think about changing your build setting to build with this new provisioning.

First of all, open your project in Xcode by clicking on it in the sidebar, then click on the Capabilities tab. Make sure Push Notifications is ON, and that both checks are green.

Xcode Capabilities

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

To register the current device for remote push notifications, call the method [BatchPush registerForRemoteNotifications] in your application delegate or wherever it is appropriate.

@import Batch;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {  
    // Start Batch.
    [Batch startWithAPIKey:@"YOUR_API_KEY"]; 

    // Register for push notifications
    [BatchPush registerForRemoteNotifications];

    return YES;
}
import Batch

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Start Batch.
    Batch.start(withAPIKey: "YOUR_API_KEY")

    // Register for push notifications
    BatchPush.registerForRemoteNotifications()

    return true
}

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): X

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

Troubleshooting
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: