Integrate the iOS SDK
You can integrate the Mobile App Messaging SDK into your iOS app to enable push notifications and user engagement features.
Add the Mobile App Messaging SDK dependencies to your project. There are three ways to add these dependencies:
- Add the SDK Dependencies with CocoaPods
- Add the SDK Dependencies with Swift Package Manager
- Add the SDK Dependencies Manually
Complete one of these processes before you continue.
The configuration example in this section uses the MarketingCloudSDK ConfigBuilder configuration method. This method is the most flexible way to use the Mobile App Messaging SDK.
All method names contain the prefix sfmc_. Using this prefix helps avoid namespace collisions between the external libraries it uses. For more information, see Apple Developer Documentation: Customizing Existing Classes.
Configure the SDK in your application using mamAppID, mamAccessToken, mamServerURL, and mamTenantId.
iOS Data Protection affects the SDK as described in this table.
| iOS Data Protection Level | SDK Behavior |
|---|---|
| No protection | SDK works in the foreground and background. |
| Complete until first user authentication | SDK works in the foreground and background after first unlock. |
| Complete unless open | SDK works in the foreground and background after first unlock. |
| Complete | SDK works only in the foreground after the device is unlocked. |
Before you enable push notifications, provision your app for push notifications.
-
Enable push notifications in your target’s Capabilities settings.
-
Set your
AppDelegateclass to adhere to theUIApplicationDelegateandUNUserNotificationCenterDelegateprotocol. -
Extend the SDK configuration code outlined in Configure the SDK to add support for push registration.
-
Add the required
UIApplicationDelegateprotocol methods to support push registration to yourAppDelegateclass. -
Add the required
UNUserNotificationCenterDelegateprotocol methods to support push notifications to yourAppDelegateclass.