Migration Guide - SDK X 10.5.0
This migration guide will walk you through the steps you need to take in order to migrate from SDK X 10.4.x and below to SDK X 10.5.0 and above.
Intro
With SDK X 10.5.0, we have made changes to some public APIs. If you are upgrading from SDK X 10.4.x or below, this page documents the changes you will need to make in your app after upgrading to SDK X 10.5.0. If you are integrating SDK X 10.5.0 or above from scratch, please refer Getting Started page instead.
Deprecated APIs
The existing push notification handling API - handleNotification:withUserInfoDictionary:isAppLaunch: - has been marked as deprecated. You should replace it's usage with one of the new APIs - based on the calling context.
Replace usage of deprecated API in userNotificationCenter:willPresent:withCompletionHandler: with handleForegroundNotification:withCompletionHandler: -
// DEPRECATED
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSDictionary *userInfo = notification.request.content.userInfo;
NSString *origin = userInfo[@"origin"];
if([@"helpshift" isEqualToString:origin]) {
[Helpshift handleNotificationWithUserInfoDictionary:userInfo
isAppLaunch:NO];
completionHandler(UNNotificationPresentationOptionNone);
} else {
// Handling for non-helpshift push notifications received when app is in foreground
}
}
// REPLACEMENT
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSDictionary *userInfo = notification.request.content.userInfo;
NSString *origin = userInfo[@"origin"];
if([@"helpshift" isEqualToString:origin]) {
[Helpshift handleForegroundNotification:userInfo
withCompletionHandler:completionHandler];
} else {
// Handling for non-helpshift push notifications received when app is in foreground
}
}
Replace usage of deprecated API in userNotificationCenter:didReceive:withCompletionHandler: with handleBackgroundNotificationClick:withCompletionHandler: -
// DEPRECATED
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
NSDictionary *userInfo = response.notification.request.content.userInfo;
NSString *origin = userInfo[@"origin"];
if([@"helpshift" isEqualToString:origin]) {
[Helpshift handleNotificationWithUserInfoDictionary:userInfo
isAppLaunch:YES];
} else {
// Handling for non-helpshift push notifications received when app is in background or killed
}
}
// REPLACEMENT
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
NSDictionary *userInfo = response.notification.request.content.userInfo;
NSString *origin = userInfo[@"origin"];
if([@"helpshift" isEqualToString:origin]) {
[Helpshift handleBackgroundNotificationClick:userInfo
withCompletionHandler:completionHandler];
} else {
// Handling for non-helpshift push notifications received when app is in background or killed
}
}
New APIs
SDK X 10.5.0 introduces following new APIs for handling push notifications. For full details on how to configure push notifications in your app, please refer the Notifications page.
- API for handling notifications received when app is in foreground
API signature - handleForegroundNotification:withCompletionHandler:
Purpose - Handle notification received when app is in foreground. Meant to be called from userNotificationCenter:willPresent: system method. Check this section for usage.
- API for handling notifications received when is in background/terminated
API signature - handleBackgroundNotificationClick:withCompletionHandler:
Purpose - Handle notification clicked when app is in background. Meant to be called from userNotificationCenter:didReceive: system method. Check this section for usage.
- API for handling notifications in NotificationService extension
API signature - handleBackgroundNotification:withContentHandler:
Purpose - Handle notification received by app's NotificationService extension. Meant to be called from didReceive:withContentHandler: notification service method. Check this section for usage.