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];
This must be done before [BatchSDK 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:
funcapplication(_application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [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();returntrue}funcapplication(_application: UIApplication, didRegisterForRemoteNotificationsWithDeviceTokendeviceToken: Data) { BatchPush.handleDeviceToken(deviceToken)}
- (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];
}
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:
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.