Skip to main content

iOS SDK Functions

Complete reference for the Told iOS SDK API.

initSDK

Initialize the SDK. Must be called before any other function, typically in your AppDelegate.

let configuration = ToldConfiguration(
sourceId: "YOUR_SOURCE_ID",
applicationId: Bundle.main.bundleIdentifier ?? "",
environment: .production,
appVersion: "1.0.0"
)
Told.initSDK(configuration)
ParameterTypeDescription
sourceIdStringYour source ID from the Told dashboard
applicationIdStringYour app's bundle identifier
environmentToldEnvironment.production, .preproduction, or .development
appVersionStringYour app version
previewBoolEnable preview mode (optional, defaults to false)

You can also pass optional parameters for logging:

Told.initSDK(configuration, logHandler: myLogHandler, debug: true)
ParameterTypeDescription
logHandlerLogHandler?Custom log handler conforming to the LogHandler protocol (optional)
debugBoolEnable debug-level logging (optional, defaults to false)

Custom LogHandler

Implement the LogHandler protocol to receive SDK logs:

class MyLogHandler: LogHandler {
func log(level: LogLevel, message: String) {
// level can be .info, .debug, or .error
print("[\(level)] \(message)")
}
}

ToldEnvironment

EnvironmentServer URLWidget URL
.productionhttps://api.told.club/graphqlhttps://widget.told.club
.preproductionhttps://preprodapi.told.club/graphqlhttps://preprodwidget.told.club
.developmenthttps://testapi.told.club/graphqlhttps://testwidget.told.club

identify

Update the current user's information. Call this when the user logs in or when their profile changes.

Told.identify(properties: ["id": "user_123", "name": "Jane", "email": "[email protected]"])
ParameterTypeDescription
properties[String: AnyHashable]Key-value pairs of user properties

Set language

Override automatic language detection by passing language in the properties:

Told.identify(properties: ["language": "en"])

trackEvent

Send a custom event for triggering surveys:

Told.trackEvent("purchase_completed", properties: ["amount": 49.99])
ParameterTypeDescription
eventNameStringName of the event
properties[String: AnyHashable]Additional event properties (optional, defaults to [:])

activateAutomaticScreenTracking

Enable automatic tracking of screen changes using method swizzling on UIViewController.viewDidAppear(_:):

Told.activateAutomaticScreenTracking()
info

SwiftUI views managed by UIHostingController are tracked, but pure SwiftUI navigation without UIKit backing may not be detected. Use trackChangePage for those cases.


deactivateAutomaticScreenTracking

Disable automatic screen tracking:

Told.deactivateAutomaticScreenTracking()

trackChangePage

Manually track a page/screen change. Use this for SwiftUI or custom navigation where automatic screen tracking does not apply:

Told.trackChangePage("SettingsScreen")
ParameterTypeDescription
pageNameStringName of the screen/page. Must match the trigger configuration in the Told dashboard.

start

Manually start a specific survey by ID:

Told.start(surveyId: "SURVEY_ID", delay: 0)
ParameterTypeDescription
surveyIdStringThe survey ID from the Told dashboard
delayTimeIntervalDelay in seconds before showing the survey (optional, defaults to 0)

reset

Reset the user to anonymous state. Call this when the user logs out. The SDK configuration is preserved.

Told.reset()

debugWidget

Log diagnostic information about your source and surveys (info log level):

Told.debugWidget()