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)
| Parameter | Type | Description |
|---|---|---|
sourceId | String | Your source ID from the Told dashboard |
applicationId | String | Your app's bundle identifier |
environment | ToldEnvironment | .production, .preproduction, or .development |
appVersion | String | Your app version |
preview | Bool | Enable preview mode (optional, defaults to false) |
You can also pass optional parameters for logging:
Told.initSDK(configuration, logHandler: myLogHandler, debug: true)
| Parameter | Type | Description |
|---|---|---|
logHandler | LogHandler? | Custom log handler conforming to the LogHandler protocol (optional) |
debug | Bool | Enable 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
| Environment | Server URL | Widget URL |
|---|---|---|
.production | https://api.told.club/graphql | https://widget.told.club |
.preproduction | https://preprodapi.told.club/graphql | https://preprodwidget.told.club |
.development | https://testapi.told.club/graphql | https://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]"])
| Parameter | Type | Description |
|---|---|---|
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])
| Parameter | Type | Description |
|---|---|---|
eventName | String | Name 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()
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")
| Parameter | Type | Description |
|---|---|---|
pageName | String | Name 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)
| Parameter | Type | Description |
|---|---|---|
surveyId | String | The survey ID from the Told dashboard |
delay | TimeInterval | Delay 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()