Migrate iOS Apps to Version 11 of the SDK

Upgrading to version 11 is a sequential process. To ensure a successful integration, you must first complete the version 10 migration before applying the final version 11 updates.

The process for migrating your iOS apps to version 11 of the SDK depends on which features you use. To start the process of migrating your apps, use this code example to update the initialization code in your app to use version 11 of the SDK.

1// Marketing Cloud SDK Configuration
2let mcAppID = "<your MC appID here>"
3let mcAccessToken = "<your MC accessToken here>"
4let mcServerURL = "<your mc serverURL here>"
5let mcMid = "<your account MID here>"
6
7// Define features of Marketing Cloud your app will use.
8let mcInboxEnabled = false
9let mcLocationEnabled = false
10let mcAnalyticsEnabled = true
11
12// MarketingCloud SDK: REQUIRED IMPLEMENTATION
13@discardableResult
14
15func configureSdk() -> Bool {
16
17    var configBuilder = ConfigBuilder()
18
19    // Enable logging for debugging early on. Debug level is not recommended for production apps, as significant data
20    // about the SDK will be logged to the console.
21
22    #if DEBUG
23            SFMCSdk.setLogger(logLevel: .debug)
24    #endif
25
26    // Use the `MarketingCloudSdkConfigBuilder` to configure the MarketingCloud SDK. This gives you the maximum flexibility in SDK configuration.
27    // The builder lets you configure the module parameters at runtime.
28
29    let engagementConfiguration = MarketingCloudSdkConfigBuilder(appId: mcAppID)
30            .setAccessToken(mcAccessToken)
31            .setMarketingCloudServerUrl(URL(string: mcServerURL)!)
32            .setMid(mcMid)
33            .setInboxEnabled(mcInboxEnabled)
34            .setLocationEnabled(mcLocationEnabled)
35            .setAnalyticsEnabled(mcAnalyticsEnabled)
36            .build()
37
38    configBuilder = configBuilder
39        .setEngagement(config: engagementConfiguration)
40
41    let pushFeatureConfiguration = PushFeatureConfigBuilder()
42        .setApplicationControlsBadging(true)
43        .build()
44
45    configBuilder = configBuilder
46        .setPushFeature(config: pushFeatureConfiguration)
47
48    // InAppMessageFeatureConfiguration
49    let iamFeatureConfiguration = InAppMessagingFeatureConfigBuilder()
50        .setEventDelegate(self)
51        .setURLHandlingDelegate(self)
52        .setInAppMessageFont(name: "HelveticaNeue")
53    // Configures which permissions the iOS system dialog requests when the user taps a Push Primer in-app message button (defaults to [.alert, .sound, .badge] if not set).
54        // .setNotificationAuthorizationOptions([.alert, .sound, .badge])
55        .build()
56    configBuilder = configBuilder
57        .setInAppMessagingFeature(config: iamFeatureConfiguration)
58
59    // Set the completion handler to take action when all modules initialization is completed.
60    // Seting the completion handler is optional.
61
62    let completionHandler: ((_ status: [ModuleInitStatus]) -> Void) = { [weak self] status in
63        DispatchQueue.main.async {
64            self?.handleSDKInitializationCompletion(status: status)
65        }
66    }
67
68    SFMCSdk.initializeSdk(configBuilder.build(), completion: completionHandler)
69
70    return true
71}
72
73// MARK: - SDK Initialization Completion Handler
74
75private func handleSDKInitializationCompletion(status: [ModuleInitStatus]) {
76    var allSuccessful = true
77
78    for moduleStatus in status {
79        print("Module: \(moduleStatus.moduleName.rawValue), Status: \(moduleStatus.initStatus.rawValue)")
80
81        if moduleStatus.initStatus == .success {
82            // Handle successful initialization for each module
83            switch moduleStatus.moduleName {
84            case .engagement:
85                // Handle successful initialization for Marketing cloud module
86            case .pushFeature:
87                // Handle successful initialization for Push Feature module
88            case .inappMessagingFeature:
89                // Handle successful initialization for In-App Feature module
90            default:
91                break
92            }
93        } else if moduleStatus.initStatus == .error {
94            allSuccessful = false
95            // module failed to initialize, check logs for more details
96        } else if moduleStatus.initStatus == .cancelled {
97            allSuccessful = false
98            // module initialization was cancelled (for example due to re-confirguration triggered before init was completed)
99        } else if moduleStatus.initStatus == .timeout {
100            allSuccessful = false
101            // module failed to initialize due to timeout, check logs for more details
102        }
103    }
104    if allSuccessful {
105        print("SDK initialization completed successfully")
106    } else {
107        print("SDK initialization completed with errors - check logs above")
108    }
109 }

Next, update the code in your app for the features you use.