Skip to main content

iOS DataSapien

info

This documentation is for iOS SDK 2.1.x

DataSapien is the main entry point of the SDK. All members are static. Use it to initialize the SDK, run the post-initialization setup, and obtain the service instances.

Functions

initialize

public static func initialize(dataSapienConfig: DataSapienConfig)

Initializes the SDK with the given configuration.

Parameters:

setup

public static func setup(
onSuccess: @escaping () -> Void,
onError: @escaping (Error) -> Void
)

Runs post-initialization setup: performs pending migrations and synchronizes MeData definitions, journeys, rules, managed APIs, segment subscriptions, managed AI models, and audiences.

Parameters:

  • onSuccess: () -> Void — Called when setup completes successfully.
  • onError: (Error) -> Void — Called when an error occurs during setup.

syncAll

public static func syncAll(
onSuccess: @escaping () -> Void,
onError: @escaping (Error) -> Void
)

Re-synchronizes all backend-driven data: MeData definitions, natively collected MeData, journeys, rules, managed APIs, segment subscriptions, managed AI models, and audiences. Use it to refresh SDK data while the app is running, for example on pull-to-refresh.

Parameters:

  • onSuccess: () -> Void — Called when synchronization completes successfully.
  • onError: (Error) -> Void — Called when an error occurs during synchronization.

deleteAllData

public static func deleteAllData()

Deletes all data stored by the SDK on the device.

Parameters: None.

getMeDataService

public static func getMeDataService() -> MeDataService

Returns the MeData Service instance.

Parameters: None.

getJourneyService

public static func getJourneyService() -> JourneyService

Returns the Journey Service instance.

Parameters: None.

getAudienceService

public static func getAudienceService() -> AudienceService

Returns the Audience Service instance.

Parameters: None.

getIntelligenceService

public static func getIntelligenceService() -> IntelligenceService

Returns the Intelligence Service instance.

Parameters: None.

getManagedApiService

public static func getManagedApiService() -> ManagedAPIService

Returns the Managed API Service instance.

Parameters: None.

getBackupService

public static func getBackupService() -> BackupService

Returns the Backup Service instance.

Parameters: None.

getHostService

public static func getHostService() -> HostService

Returns the Host Service instance.

Parameters: None.

Classes

DataSapienConfig

Configuration for SDK initialization. Instances are created via the nested Builder.

DataSapienConfig.Builder

public class Builder {
public init()

public func setAuth(
url authUrl: String,
clientId authClientId: String,
clientSecret authClientSecret: String,
scope authScope: String
) -> Builder

public func setHost(
baseUrl hostUrl: String,
mediaUrl mediaURL: String
) -> Builder

public func setLogLevel(_ levels: [LogLevel]) -> Builder
public func setDebugViewEnabled(_ enabled: Bool) -> Builder
public func setmainColor(_ mainColor: UIColor) -> Builder
public func setCustomCssURL(_ url: URL?) -> Builder
public func setAppGroupID(_ appGroupID: String) -> Builder
public func build() -> DataSapienConfig
}
  • setAuth — OAuth token endpoint URL, client ID, client secret, and scope. Required.
  • setHost — Base URL for the DataSapien API and base URL for the DataSapien media API. Required.
  • setLogLevel — Sets which log levels the SDK emits (see LogLevel). Optional; an empty array (the default) disables all SDK logging.
  • setDebugViewEnabled — Enables the Journey in-app debug view. Optional, defaults to false.
  • setmainColor — Main color used for UI styling. Optional.
  • setCustomCssURL — URL of a custom CSS file used for Journey UI styling. Optional.
  • setAppGroupID — App Group identifier used to share SDK storage with app extensions. Optional.
  • build — Builds the configuration.

Example:

let config = DataSapienConfig
.Builder()
.setAuth(
url: "<YOUR_AUTH_URL>",
clientId: "<YOUR_CLIENT_ID>",
clientSecret: "<YOUR_CLIENT_SECRET>",
scope: "<YOUR_AUTH_SCOPE>"
)
.setHost(
baseUrl: "<YOUR_HOST_URL>",
mediaUrl: "<YOUR_MEDIA_URL>"
)
.setLogLevel([.warning, .error])
.setDebugViewEnabled(true)
.build()

DataSapien.initialize(dataSapienConfig: config)

LogLevel

public enum LogLevel: String {
case debug = "DEBUG"
case info = "INFO"
case warning = "WARNING"
case error = "ERROR"
}