Integrate the MobilePush iOS SDK
You can implement the MobilePush iOS SDK using CocoaPods, Swift Package Manager (SPM), or manually. Depending on your preferred implementation methods, refer to the following sections:
- Implement the SDK with CocoaPods
- Implement the SDK with Swift Package Manager
- Implement the SDK Manually
To add the SDK as a dependency in your app's Podfile, follow the instructions for Adding Pods to an Xcode project on CocoaPods' documentation site.
Next, open the .xcworkspace
created by the install process using Xcode and start using the SDK.
Avoid opening .xcodeproj
directly. Opening a project file instead of a workspace can lead to errors.
Starting with version 8.0.0 of the MobilePush iOS SDK, you can implement the SDK using SPM by doing the following:
-
In your Xcode project, go to the Package Dependencies tab of your project's settings.
-
Add a package by clicking the plus sign (+).
-
Search for the package
MarketingCloudSDK
using the urlhttps://github.com/salesforce-marketingcloud/MarketingCloudSDK-iOS.git
-
Select the package to include it in your app.
If you’re looking to migrate from older versions of the SDK to the 8.x version, see Migrate to the Next-Gen MobilePush SDK for iOS.
To implement the SDK manually, do the following:
-
Download the SDK.
-
Copy the
MarketingCloudSDK
directory from your downloads to your project directory. -
Open your application project and select the appropriate target.
-
Add
MarketingCloudSDK.xcframework
to Frameworks, Libraries, and Embedded Content in your target’s General settings. -
Add
MarketingCloudSDK.bundle
to Copy Bundle Resources in your target’s Build Phases settings. -
Add
-ObjC
to your target’s Other Linker Flags build settings.
For reference documentation on SDK configuration methods, refer to the following links:
- For MobilePush iOS SDK versions 7.x:
MarketingCloudSDK
- For MobilePush iOS SDK versions 8.x:
PushModule
The configuration example in this section uses the MarketingCloudSDK ConfigBuilder
configuration method, as it’s the most flexible means to support your application’s usage of MobilePush.
Configuration of the SDK using a JSON file (included in our GitHub repository) is deprecated. We encourage you to move existing implementations to the builder method. For more information on our configuration methods, see the MarketingCloudSDKConfigBuilder
reference for SDK versions 7.x and the PushConfigBuilder
reference for SDK versions 8.x.
All method names contain the prefix sfmc_. This convention allows the application implementing the SDK to avoid namespace collisions between the external libraries it uses. The MarketingCloudSDK
doesn’t cause compile, link, or runtime collisions with other code your application implements. For more information, see Apple's documentation on Customizing Existing Classes.
Configure the SDK in your application using the Access Token
, App ID
, App Endpoint
, and MID
values noted when you Retrieve Required SDK Configuration Data.
Enable or disable analytics
, location
, or inbox
entries depending on the application's needs and your usage of Marketing Cloud Engagement.
iOS Data Protection affects the SDK as described in the following 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 enabling push notifications, make sure you've provisioned your app for push notifications, as outlined in Provision Your App for Push with Apple.
-
Enable push notifications in your target’s Capabilities settings.
-
Set your
AppDelegate
class to adhere to theUIApplicationDelegate
andUNUserNotificationCenterDelegate
protocol. -
Extend the SDK configuration code outlined in Configure the SDK to add support for push registration.
-
Add the required
UIApplicationDelegate
protocol methods to support push registration to yourAppDelegate
class. -
Add the required
UNUserNotificationCenterDelegate
protocol methods to support push notifications to yourAppDelegate
class.The methods described in the preceding instructions use
MarketingCloud
SDK APIs to facilitate the framework’s functionality to manage push notifications, which include MobilePush contact registration and push analytics tracking.If you implement the methods without using the
MarketingCloud
SDK methods as demonstrated, MobilePush functionality doesn't work as expected. Additionally, if you choose not to implement these methods altogether, MobilePush functionality doesn't work at all.