iOS > Advanced

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:

[BatchPush disableAutomaticIntegration];
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:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [BatchPush disableAutomaticIntegration];
    [Batch startWithAPIKey:@"KEY"];
    [BatchPush registerForRemoteNotifications];

    return YES;
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    [BatchPush handleRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    [BatchPush handleDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [BatchPush handleNotification:userInfo];
}

// Alternatively, implement this one:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    [BatchPush handleNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

// This is only needed if you use actionable notifications

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
{
    [BatchPush handleNotification:userInfo actionIdentifier:identifier];
    completionHandler();
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    BatchPush.disableAutomaticIntegration()
    Batch.start(withAPIKey: "YOUR API KEY")
    BatchPush.registerForRemoteNotifications()

    return true
}

func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {

    BatchPush.handleRegister(notificationSettings)
}

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

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
}

// This is only needed if you use actionable notifications

func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [AnyHashable : Any], completionHandler: @escaping () -> Void) {
    BatchPush.handleNotification(userInfo, actionIdentifier: identifier)
    completionHandler()
}

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