|
| 1 | +--- |
| 2 | +sidebar_position: 145 |
| 3 | +title: Migration Guide - SDK X 10.5.0 |
| 4 | +description: "This migration guide will walk you through the steps you need to take in order to migrate from SDK X 10.4.1 and below to SDK X 10.5.0 and above" |
| 5 | +--- |
| 6 | + |
| 7 | +import { |
| 8 | + Admonition, |
| 9 | + CodeBlock, |
| 10 | + Tabs, |
| 11 | + TabItem, |
| 12 | + Intro, |
| 13 | +} from "@site/src/components/forDocs"; |
| 14 | + |
| 15 | +<Intro> |
| 16 | + |
| 17 | +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. |
| 18 | + |
| 19 | +</Intro> |
| 20 | + |
| 21 | +# Intro |
| 22 | + |
| 23 | +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](/sdkx_ios/getting-started) page instead. |
| 24 | + |
| 25 | +## Deprecated APIs {#deprecated-apis} |
| 26 | + |
| 27 | + |
| 28 | +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. |
| 29 | + |
| 30 | +Replace usage of deprecated API in `userNotificationCenter:willPresent:withCompletionHandler:` with `handleForegroundNotification:withCompletionHandler:` - |
| 31 | + |
| 32 | +<Tabs groupId="ios-languages"> |
| 33 | +<TabItem value="Objective-C" label="Objective-C"> |
| 34 | + |
| 35 | +```objc |
| 36 | +// DEPRECATED |
| 37 | +- (void)userNotificationCenter:(UNUserNotificationCenter *)center |
| 38 | + willPresentNotification:(UNNotification *)notification |
| 39 | + withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler |
| 40 | +{ |
| 41 | + NSDictionary *userInfo = notification.request.content.userInfo; |
| 42 | + NSString *origin = userInfo[@"origin"]; |
| 43 | + |
| 44 | + if([@"helpshift" isEqualToString:origin]) { |
| 45 | + [Helpshift handleNotificationWithUserInfoDictionary:userInfo |
| 46 | + isAppLaunch:NO]; |
| 47 | + completionHandler(UNNotificationPresentationOptionNone); |
| 48 | + } else { |
| 49 | + // Handling for non-helpshift push notifications received when app is in foreground |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +// REPLACEMENT |
| 54 | +- (void)userNotificationCenter:(UNUserNotificationCenter *)center |
| 55 | + willPresentNotification:(UNNotification *)notification |
| 56 | + withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler |
| 57 | +{ |
| 58 | + NSDictionary *userInfo = notification.request.content.userInfo; |
| 59 | + NSString *origin = userInfo[@"origin"]; |
| 60 | + |
| 61 | + if([@"helpshift" isEqualToString:origin]) { |
| 62 | + [Helpshift handleForegroundNotification:userInfo |
| 63 | + withCompletionHandler:completionHandler]; |
| 64 | + } else { |
| 65 | + // Handling for non-helpshift push notifications received when app is in foreground |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +</TabItem> |
| 71 | +<TabItem value="Swift" label="Swift"> |
| 72 | + |
| 73 | +```swift |
| 74 | +// DEPRECATED |
| 75 | +func userNotificationCenter( |
| 76 | + _ center: UNUserNotificationCenter, |
| 77 | + willPresent notification: UNNotification, |
| 78 | + withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void |
| 79 | +) { |
| 80 | + if notification.request.content.userInfo["origin"] as? String == "helpshift" { |
| 81 | + Helpshift.handleNotification(withUserInfoDictionary: notification.request.content.userInfo, isAppLaunch: false) |
| 82 | + completionHandler([]) |
| 83 | + } else { |
| 84 | + // Handling for non-helpshift push notifications received when app is in foreground |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +// REPLACEMENT |
| 89 | +func userNotificationCenter( |
| 90 | + _ center: UNUserNotificationCenter, |
| 91 | + willPresent notification: UNNotification, |
| 92 | + withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void |
| 93 | +) { |
| 94 | + if notification.request.content.userInfo["origin"] as? String == "helpshift" { |
| 95 | + Helpshift.handleForegroundNotification(userInfo, withCompletionHandler: completionHandler) |
| 96 | + } else { |
| 97 | + // Handling for non-helpshift push notifications received when app is in foreground |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +</TabItem> |
| 103 | +</Tabs> |
| 104 | + |
| 105 | +Replace usage of deprecated API in `userNotificationCenter:didReceive:withCompletionHandler:` with `handleBackgroundNotificatinClick:withCompletionHandler:` - |
| 106 | + |
| 107 | +<Tabs groupId="ios-languages"> |
| 108 | +<TabItem value="Objective-C" label="Objective-C"> |
| 109 | + |
| 110 | +```objc |
| 111 | +// DEPRECATED |
| 112 | +- (void)userNotificationCenter:(UNUserNotificationCenter *)center |
| 113 | + didReceiveNotificationResponse:(UNNotificationResponse *)response |
| 114 | + withCompletionHandler:(void (^)(void))completionHandler |
| 115 | +{ |
| 116 | + NSDictionary *userInfo = response.notification.request.content.userInfo; |
| 117 | + NSString *origin = userInfo[@"origin"]; |
| 118 | + if([@"helpshift" isEqualToString:origin]) { |
| 119 | + [Helpshift handleNotificationWithUserInfoDictionary:userInfo |
| 120 | + isAppLaunch:YES]; |
| 121 | + } else { |
| 122 | + // Handling for non-helpshift push notifications received when app is in background or killed |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +// REPLACEMENT |
| 127 | +- (void)userNotificationCenter:(UNUserNotificationCenter *)center |
| 128 | + didReceiveNotificationResponse:(UNNotificationResponse *)response |
| 129 | + withCompletionHandler:(void (^)(void))completionHandler |
| 130 | +{ |
| 131 | + NSDictionary *userInfo = response.notification.request.content.userInfo; |
| 132 | + NSString *origin = userInfo[@"origin"]; |
| 133 | + if([@"helpshift" isEqualToString:origin]) { |
| 134 | + [Helpshift handleBackgroundNotificationClick:userInfo |
| 135 | + withCompletionHandler:completionHandler]; |
| 136 | + } else { |
| 137 | + // Handling for non-helpshift push notifications received when app is in background or killed |
| 138 | + } |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +</TabItem> |
| 143 | +<TabItem value="Swift" label="Swift"> |
| 144 | + |
| 145 | +```swift |
| 146 | +// DEPRECATED |
| 147 | +func userNotificationCenter( |
| 148 | + _ center: UNUserNotificationCenter, |
| 149 | + didReceive response: UNNotificationResponse, |
| 150 | + withCompletionHandler completionHandler: @escaping () -> Void |
| 151 | +) { |
| 152 | + if response.notification.request.content.userInfo["origin"] as? String == "helpshift" { |
| 153 | + Helpshift.handleNotification(withUserInfoDictionary: response.notification.request.content.userInfo, isAppLaunch: true) |
| 154 | + } else { |
| 155 | + // Handling for non-helpshift push notifications received when app is in background or killed |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | +// REPLACEMENT |
| 160 | +func userNotificationCenter( |
| 161 | + _ center: UNUserNotificationCenter, |
| 162 | + didReceive response: UNNotificationResponse, |
| 163 | + withCompletionHandler completionHandler: @escaping () -> Void |
| 164 | +) { |
| 165 | + if response.notification.request.content.userInfo["origin"] as? String == "helpshift" { |
| 166 | + Helpshift.handleBackgroundNotificationClick(response.notification.request.content.userInfo, withCompletionHandler: completionHandler) |
| 167 | + } else { |
| 168 | + // Handling for non-helpshift push notifications received when app is in background or killed |
| 169 | + } |
| 170 | +} |
| 171 | +``` |
| 172 | + |
| 173 | +</TabItem> |
| 174 | +</Tabs> |
| 175 | + |
| 176 | +## Removed APIs {#removed-apis} |
| 177 | + |
| 178 | +Following APIs that were deprecated in older versions of the SDK have now been removed altogether. The replacement APIs are mentioned alongside. If you are using any of the removed APIs in your app, you will get compilation errors. So it is essential to migrate to the replacement APIs in this case. |
| 179 | + |
| 180 | +| Removed API | Replacement API | |
| 181 | +|------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------| |
| 182 | +| `clearAnonymousUserOnLogin` | `clearAnonymousUserOnLogin:` - Pass boolean true to clear/false to not clear | |
| 183 | +| `showConversationWith:config:` | `showConversationWithConfig:` - No need to pass in view controller | |
| 184 | +| `showFAQsWith:config:` | `showFAQsWithConfig:` - No need to pass in view controller | |
| 185 | +| `showFAQSection:with:config:` | `showFAQSection:withConfig:` - No need to pass in view controller | |
| 186 | +| `showSingleFAQ:with:config:` | `showSingleFAQ:withConfig:` - No need to pass in view controller | |
| 187 | +| `handleNotificationWithUserInfoDictionary:isAppLaunch:withController:` | `handleForegroundNotification:withCompletionHandler:` - When notification is received in foreground | |
| 188 | +| `handleNotificationWithUserInfoDictionary:isAppLaunch:withController:` | `handleBackgroundNotificationClick:withCompletionHandler:` - When notification is clicked in background | |
| 189 | + |
| 190 | +## New APIs {#new-apis} |
| 191 | + |
| 192 | +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](/sdkx_ios/notifications) page. |
| 193 | + |
| 194 | +1. **API for handling notifications received when app is in foreground** |
| 195 | + |
| 196 | +**API signature** - `handleForegroundNotification:withCompletionHandler:` |
| 197 | + |
| 198 | +**Purpose** - Handle notification received when app is in foreground. Meant to be called from `userNotificationCenter:willPresent:` system method. Check [this section](/sdkx_ios/notifications/#push-delegates-foreground) for usage. |
| 199 | + |
| 200 | +2. **API for handling notifications received when is in background/terminated** |
| 201 | + |
| 202 | +**API signature** - `handleBackgroundNotificationClick:withCompletionHandler:` |
| 203 | + |
| 204 | +**Purpose** - Handle notification clicked when app is in background. Meant to be called from `userNotificationCenter:didReceive:` system method. Check [this section](/sdkx_ios/notifications/#push-delegates-background) for usage. |
| 205 | + |
| 206 | +3. **API for handling notifications in NotificationService extension** |
| 207 | + |
| 208 | +**API signature** - `handleBackgroundNotification:withContentHandler:` |
| 209 | + |
| 210 | +**Purpose** - Handle notification received by app's NotificationService extension. Meant to be called from `didReceive:withContentHandler:` notification service method. Check [this section](/sdkx_ios/notifications/#notification-service) for usage. |
| 211 | + |
| 212 | + |
| 213 | + |
0 commit comments