The MobilePush SDK version 8.x update sets a more modern architectural foundation to enable a variety of improvements and all new features for future versions. The updated MobilePush SDK is designed with existing MobilePush customers in mind so that the upgrade path is light and straightforward.
To migrate to MobilePush SDK version 8 or later, follow these steps.
If you use version 8.0.13 or earlier of the SDK, add the SFMCSDK (tag 1.x) and MobilePush (tag 8.x) dependencies to your application target.
Manually pull the Resources/MarketingCloudSDK.bundle from the sources folder in the MarketingCloudSDK Swift module and add it as a resource within Copy Bundle Resources in the build phase configuration. If you don’t complete this step, you’ll encounter this error: Thread 1: Cannot create an NSPersistentStoreCoordinator with a nil model.
Initialize the SDK
You must replace your existing initialization function to reference the new SDK. After you’ve fetched the updated SDK version in your project, the functions that must be modified are highlighted in your codebase.
Update the configuration builder function as shown in this example.
Ensure that the SDK has initialized correctly by using a check on the status of initialization or by using the completion handler, as shown in this example.
1// Old23let builder = MarketingCloudSDKConfigBuilder()4 .sfmc_setApplicationId(appID)5 .sfmc_setAccessToken(accessToken)6 .sfmc_setMarketingCloudServerUrl(appEndpoint)7 .sfmc_build()!89var success = false1011do{12 try MarketingCloudSDK.sharedInstance().sfmc_configure(with:builder)13 success = true14}catch let error as NSError{15 // error logic16}1718if success == true{19 //function logic20}2122// New2324// With manual check on the module initialization success25let configuration = PushConfigBuilder(appId: PUSH_APP_ID)26 .setAccessToken(PUSH_ACCESS_TOKEN)27 .setMarketingCloudServerUrl(URL(string: PUSH_TSE)!)28 .build()2930SFMCSdk.initializeSdk(ConfigBuilder().setPush(config: configuration).build())3132if SFMCSdk.mp.getStatus() == .operational {33 //function logic34}3536// Or with using the completion handler37let configuration = PushConfigBuilder(appId: PUSH_APP_ID)38 .setAccessToken(PUSH_ACCESS_TOKEN)39 .setMarketingCloudServerUrl(URL(string: PUSH_TSE)!)40 .build()4142SFMCSdk.initializeSdk(ConfigBuilder()43 .setPush(44 config: configuration,45 onCompletion: {result in print("TODO, Module initialization result is: \(result.rawValue)")}46).build())
Update Identity Functions
Set the identity or ID of a known user: Replace your current identity tracking function setContactKey with the updated function setProfileID.
Set the Attributes of a user: Replace your existing identity tracking function setAttribute with the updated function setProfileAttributes.
Align your existing functions with updated functions provided by the new SDK. All existing functions that need changes are marked as deprecated in your codebase.
Capture Notifications On Launch (Only for 8.0.x)
If you’re using version 8.1.x of the SDK, you don’t need to perform this step. Using the new requestPushSdk API enables the SDK to automatically capture notifications for you, regardless of the application’s state and the SDK initialization status. For a complete implementation example, see the iOS LearningApp.
Note
To ensure push notifications are processed accurately when your application isn’t actively running, capture them during application launch and store them in memory until the SDK initializes fully. Failing to do so prevents the SDK from processing incoming push notifications. After the SDK is operational, the notification is set to the SDK using setNotificationUserInfo API, as shown in this example.
1// Add a member variable in the AppDelegate class2@UIApplicationMain3class AppDelegate: UIResponder, UIApplicationDelegate {45 // ...67 // Notification to capture8 var notificationUserInfo:[AnyHashable:Any]?910// -----------------------------1112func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) ->Bool{1314 // Extract the notification from launchOptions15 if let options = launchOptions, let notification = options[UIApplication.LaunchOptionsKey.remoteNotification] as? [AnyHashable: Any]{16 self.notificationUserInfo = notification17}18 // ...1920 let completionHandler: (OperationResult) ->() = { result in21 if result == .success {22 // Method to call when the SDK is ready23 self.setupMobilePush()24}25}2627 // Initialize the SDK28 SFMCSdk.initializeSdk(29 ConfigBuilder().setPush(30 config: mobilePushConfiguration,31 onCompletion: completionHandler32).build()33)3435 // ...36}3738// -----------------------------3940func setupMobilePush(){41 // ...4243 // Provide the notification object to SDK when the SDK is ready.44 DispatchQueue.main.async{45 if let userInfo = self.notificationUserInfo {46 SFMCSdk.mp.setNotificationUserInfo(userInfo)47}else{48 debugPrint("No notification UserInfo: - either it should be a direct launch or Notification userInfo is not available when launched from notification")49}50}51}52}
For a complete implementation example, see the iOS LearningApp.