# 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.

{% hint style="info" %}
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.
{% endhint %}

To disable automatic integration, simply call:

{% tabs %}
{% tab title="Swift" %}

```swift
BatchPush.disableAutomaticIntegration()
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[BatchPush disableAutomaticIntegration];
```

{% endtab %}
{% endtabs %}

{% hint style="danger" %}
This must be done before `[BatchSDK startWithAPIKey:]`.
{% endhint %}

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:

{% tabs %}
{% tab title="Swift" %}

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
    BatchPush.disableAutomaticIntegration()
    BatchSDK.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)
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [BatchPush disableAutomaticIntegration];
    [BatchSDK startWithAPIKey:@"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 YES;
}

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

{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="Swift" %}

```swift
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
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec

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

- (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);
}
```

{% endtab %}
{% endtabs %}

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](https://doc.batch.com/developer/sdk/ios/advanced/intercepting-notifications).
