Manual integration

In order to make your SDK integration as easy as possible, Batch Push automatically integrates into your application delegate by using a technique called "method swizzling".

Even though we've taken the greatest care when writing our swizzling code, you may encounter some cases where you don't want that, such as:

  • Incompatibility with other SDKs that also try to integrate themselves
  • Incompatibility with third party app development solutions
  • Swizzling breaks your delegate's architecture
  • You don't want code swizzled on your behalf

That's why, starting with Batch 1.5.3, we support a fully manual integration of the SDK.

We advise that you only resort to this if swizzling is problematic. On most apps this is not a problem, but if you manually integrate, you will have to check the changelogs on each update to see if Batch requires new methods for the manual integration.

To disable automatic integration, simply call:

  • Swift
  • Objective-C
BatchPush.disableAutomaticIntegration()

Important
This must be done before [Batch startWithAPIKey:].

Then, you'll have to put calls to BatchPush where needed, in order to ensure that all Batch Push functionality works. Not implementing any of them will cause issues.

Here's a sample app delegate:

  • Swift
  • Objective-C
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
    BatchPush.disableAutomaticIntegration()
    Batch.start(withAPIKey: "YOUR API KEY")

    // You MUST have a UNUserNotificationCenterDelegate implementation.
    // Batch provides BatchUNUserNotificationCenterDelegate as a default one: if you have your own, integrate Batch into it.
    // See "Intercepting notifications" for more info.
    // Available from Batch 1.16
    BatchUNUserNotificationCenterDelegate.registerAsDelegate()

    // 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();
    
    return true
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    BatchPush.handleDeviceToken(deviceToken)
}

Legacy documentation

If using Batch 1.15 or lower on an application that supports iOS 8 and 9, you need to implement some extra methods:

  • Swift
  • Objective-C
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {

    BatchPush.handleRegister(notificationSettings)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    BatchPush.handleNotification(userInfo)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    BatchPush.handleNotification(userInfo)
    completionHandler(.newData) // Adjust the result accordingly
}

On iOS 10 and higher, you should also implement UNUserNotificationCenterDelegate. How to correctly integrate it with Batch does not change in manual mode, and is detailed in Intercepting Notifications.