Configure the SDK for iOS

After you install the SDK dependencies manually, with CocoaPods, or with Swift Package Manager, configure the SDK using the ConfigBuilder method.

Earlier versions of the SDK supported JSON file configuration, which is deprecated. If your implementation uses JSON configuration, reconfigure it using the builder method.

Use these code examples to configure the SDK in your app. Make these changes to the examples:

  • Add the Access Token, App ID, App Endpoint, and MID values that you obtained when you configured Marketing Cloud Engagement.
  • Enable or disable analytics, location, or inbox based on your app’s requirements.

Also, consider the ways that iOS Data Protection impact your app.

These examples import the SFMCSDK module, which is included automatically with the dependencies for the SDK. Never install this dependency manually (such as by using CocoaPods).

If your app uses version 10 or later of the SDK, use this code.

If your app uses version 8 or 9 of the SDK, use this code.

If your app uses version 7 of the SDK, use this code.

iOS Data Protection encrypts files stored on the device and controls when your app can access them based on the lock state of the user’s device. If your app uses Data Protection, you must configure the SDK at the right time to ensure it can access the encrypted data it needs to function. The SDK’s ability to work in the foreground or background depends on the Data Protection level you configure.

iOS Data Protection affects the SDK in these ways.

iOS Data Protection LevelSDK Behavior
No protectionSDK works in the foreground and background
Complete until first user authenticationSDK works in the foreground and background after first unlock
Complete unless openSDK works in the foreground and background after first unlock
CompleteSDK works only in the foreground after the device is unlocked

For more information, see iOS Data Protection.