Installation and configuration (iOS)
In this article, you will find out how to install and initialize the Synerise SDK in an iOS application. While performing the actions from this guide, keep the presented order.
If you want to find out what kind of benefits you can get from integrating with mobile SDK, go here.
Requirements
You need:
- Access to a workspace
- A Profile API Key
When creating the API key, use allowlisting or denylisting to only allow the events you intend to use. - One of the following dependency managers:
- CocoaPods - CocoaPods is a dependency manager for iOS projects.
- Carthage - Carthage is a simple, decentralized dependency manager for iOS projects.
- Swift Package Manager - Swift Package Manager (SPM) is a dependency manager built into Xcode.
- Recommended environment:
- Xcode 15
- iOS SDK 17
- Target deployment: iOS 9.0+
Apple Frameworks
The Synerise SDK references the following Apple frameworks:
Foundation.framework
UIKit.framework
CoreGraphics.framework
SystemConfiguration.framework
MobileCoreServices.framework
CoreTelephony.framework
Security.framework
CommonCrypto.framework
WebKit.framework
UserNotifications.framework
3rd Party Frameworks
Installation
CocoaPods
- Add CocoaPods dependency to Synerise SDK into your
Podfile
:use_frameworks! target YOUR_PROJECT_TARGET do pod 'SyneriseSDK' end
- Execute the following shell command in the directory depending on your project configuration:
pod repo update pod install
Swift Package Manager (SPM)
- Go to Xcode project’s settings and navigate to the Package Dependencies tab.
- Below the packages list, click the Add button.
- Enter the URL of Synerise SDK repository (https://github.com/Synerise/synerise-ios-sdk) in the search text field.
- Under the Dependency Rule section, select the SDK version. Finally, click Add Package.
- Select the package that best suits your needs and click Add Package.
Carthage
-
Add the Carthage dependency to Synerise SDK into your
Cartfile
:github "synerise/ios-sdk"
-
Execute the shell command in directory depending on your project configuration:
carthage update
-
Go to Xcode project target’s General section.
-
In Finder, open
<YOUR_XCODE_PROJECT_DIRECTORY>/Carthage/Build/iOS
-
Drag
SyneriseSDK.framework
to Embedded Binaries. -
Make sure the Copy items if needed option is selected.
-
Click Finish.
Initialization
Setting up
-
Go to Xcode project target’s General section.
-
Find the Other Linker Flags property and add the -ObjC flag.
-
If you are going to use push notifications:
- Go to
Info.plist
- Add a row for Required background mode with the following array type value:
App downloads content in response to push notifications
or add the code below directly:<key>UIBackgroundModes</key> <array> <string>remote-notification</string> </array>
- Go to
-
If you are going to use HTTP addresses (instead of only HTTPS), change the allowlist domains in your app by adding configuration to
Info.plist
in one of the following ways:- Add configured domain/domains that you need.
<key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>yourdomain.com</key> <dict> <!--Include to allow subdomains--> <key>NSIncludesSubdomains</key> <true/> <!--Include to allow HTTP requests--> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> <!--Include to specify minimum TLS version--> <key>NSTemporaryExceptionMinimumTLSVersion</key> <string>TLSv1.1</string> </dict> </dict> </dict>
- Give permission for all domains.
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key><true/> </dict>
- Add configured domain/domains that you need.
Importing Synerise SDK
Import the Synerise SDK header into the files that contain code relating to SDK.
import SyneriseSDK
Basic initialization
Initialize Synerise SDK and provide the Profile API Key.
You may initialize it wherever you want and when you need.
Synerise.initialize(clientApiKey: "YOUR_CLIENT_API_KEY") // 1
Synerise.setDebugModeEnabled(false) // 2
Synerise.setCrashHandlingEnabled(true) // 3
Synerise.setDelegate(self) // 4
Basic methods you need:
Synerise.initialize(clientApiKey:)
- Initializes Synerise SDK.Synerise.setDebugModeEnabled(_:)
- Enables debug mode for Synerise SDK. See Debug mode section for more information.Synerise.setCrashHandlingEnabled(_:)
- Enables crash handling. Synerise SDK sends a crash event automatically when an uncaught exception occurs.Synerise.setDelegate(_:)
- Sets delegate to handle main actions from Synerise SDK. SeeSyneriseDelegate
section for more information.
Initialization with custom API environment
To change API base URL for on-premise installations, use the following initialization method:
Synerise.initialize(clientApiKey: "YOUR_PROFILE_API_KEY", baseUrl: "YOUR_API_BASE_URL")
Advanced initialization
This is an example of advanced initialization with:
- custom API base URL for on-premise installations
- request validation salt configured
- debug mode enabled
- crash handling enabled
- most of the settings options available
- main delegate
SyneriseDelegate
- client’s state delegate
ClientStateDelegate
Synerise.initialize(clientApiKey:)
method. See Settings section for more details about settings options.clientApiKey
and requestValidationSalt
) with mechanisms like string obfuscation or encryption.Synerise.settings.sdk.enabled = true
Synerise.settings.sdk.appGroupIdentifier = "YOUR_APP_GROUP_IDENTIFIER"
Synerise.settings.sdk.keychainGroupIdentifier = "YOUR_KEYCHAIN_GROUP_IDENTIFIER"
Synerise.settings.sdk.minTokenRefreshInterval = 1800
Synerise.settings.sdk.shouldDestroySessionOnApiKeyChange = false
Synerise.settings.notifications.enabled = true
Synerise.settings.notifications.disableInAppAlerts = true
Synerise.settings.notifications.encryption = false
Synerise.settings.tracker.autotracking.enabled = true
Synerise.settings.tracker.autotracking.mode = AutoTrackMode.Fine
Synerise.settings.tracker.autotracking.excludedClasses = [SampleViewController.self]
Synerise.settings.tracker.autotracking.excludedViewTags = [0, 1, 2]
Synerise.settings.tracker.tracking.enabled = true
Synerise.settings.tracker.minBatchSize = 10
Synerise.settings.tracker.maxBatchSize = 100
Synerise.settings.tracker.autoFlushTimeout = 5.0
Synerise.settings.tracker.autoTracking.mode = .fine
Synerise.settings.tracker.locationAutomatic = true
Synerise.settings.injector.automatic = true
Synerise.initialize(clientApiKey: "YOUR_CLIENT_API_KEY", baseUrl: "YOUR_API_BASE_URL")
Synerise.setRequestValidationSalt("YOUR_REQUEST_VALIDATION_SALT")
Synerise.setDebugModeEnabled(false)
Synerise.setCrashHandlingEnabled(true)
Synerise.setDelegate(self)
Client.setClientStateDelegate(self)
Initialization process
During initialization, the library starts and when it is ready or an error occurs, the SDK notifies you.
When the delegate method is called, Synerise is ready to use.
// MARK: - SyneriseDelegate
// This method is called when the Synerise SDK is initialized.
func snr_initialized() {
//...
}
// This method is called when an error occurs while initializing the Synerise SDK.
func snr_initializationError(error: Error) {
//...
}
Debug Mode
You can enable debug logs for Synerise SDK by method Synerise.setDebugModeEnabled(_:)
.
Synerise.setDebugModeEnabled(true) // Enables logging for all modules
You can receive some logs about:
- Core: push notifications
- Tracker: auto-tracked events, declarative events, sending process
- Client: customer state, authorization
- Injector: campaigns, UI
- Promotions: promotions, vouchers
- Content: content widget, documents, recommendations
Background Tasks
Background Tasks is a mechanism to schedule and run code in the background to keep your app up to date.
Synerise supports using Background Tasks since SDK version 4.23.0. You can pass configured identifiers for Synerise SDK by using the Synerise.setBackgroundTaskIdentifiers(_:)
method. The identifiers that you are going to pass have to be configured properly in the host app.
Benefits
Currently, the SDK uses Background Tasks only to refresh the registration token for Push Notifications every 20 days. In these situations, the SDK invokes the snr_registerForPushNotificationsIsNeeded(origin:) method or snr_registerForPushNotificationsIsNeeded() method.
Setting up
To configure Background Tasks in your app:
- Go to Xcode project’s target’s Signing & Capabilities section.
- In the Background Modes capability (you may need to add it), enable Background fetch and Background processing.
- Go to
Info.plist
. - Add a row with the following array type value:
Permitted background task scheduler identifiers
. - Add string identifiers, each as a separate item to declare possible Background Tasks identifiers in your app.
- Pass these Background Tasks identifiers to SDK by using the
Synerise.setBackgroundTaskIdentifiers(_:)
method. You must invoke the method BEFORE your app is launched (before theapplication(_ application:didFinishLaunchingWithOptions launchOptions:)
method finishes).
Sample \*.plist
configuration for Background Tasks:
Example code for passing Background Tasks identifiers to the SDK:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// ...
Synerise.setBackgroundTaskIdentifiers(["YOUR_BACKGROUND_TASK_IDENTIFIER"])
return true
}
Documentation is available at Apple Developer - Using background tasks to update your app.
IMPORTANT: To configure Background Tasks properly, you must set SyneriseDelegate
before the SDK initialization.
Synerise.setDelegate(self)
Synerise.initialize(clientApiKey: "YOUR_CLIENT_API_KEY")
// ...
Privacy manifest
From 1 May 2024, Apple requires you to add a privacy manifest. It’s a file in your project that describes your reason and method for collecting data.
Third-party frameworks that track data should have a privacy manifest. When you create the application privacy report, these privacy manifest files are automatically aggregated into a single file.
Synerise supports privacy manifests since SDK version 4.17.0. When you use an SDK version older than 4.17.0, refer to the Synerise API usage requirements defined below when creating an Apple privacy manifest.
APIs usage
API | Reason | Description |
---|---|---|
User defaults APIs | CA92.1 1C8F.1 |
Synerise uses User Defaults to persist the SDK data and share them between the application and extensions |
Tracking
Synerise does not track any data that is protected by the App Tracking Transparency framework.
Collected Data
Data type | Value | Purpose |
---|---|---|
User ID | NSPrivacyCollectedDataTypeUserID | Analytics, Product Personalization |
Other usage data | NSPrivacyCollectedDataTypeOtherUsageData | Analytics, Product Personalization, App Functionality |
Product interaction | NSPrivacyCollectedDataTypeProductInteraction | Analytics |
Advertising data | NSPrivacyCollectedDataTypeAdvertisingData | Other Purposes, App Functionality |
Crash data | NSPrivacyCollectedDataTypeOtherUserContent | Analytics |
Warnings and limitations
Be careful with keychain deletion operations due to the possibility of deleting Synerise data. All the SDK library data keys are named snr.[KEY_NAME]
.