# Reference

Every public method of the Screeb iOS SDK, with its signature.

Complete reference for the Screeb iOS SDK: static methods of the `Screeb` class. New to Screeb? Start with the [install guide](https://developers.screeb.app/sdk-ios/install).

## Methods by capability

### Lifecycle

| Method                                                                                                                                                                                                                | Description                | More                                                   |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------ |
| `initSdk(context: UIViewController?, channelId: String, identity: String? = nil, visitorProperty: [String: Any] = [:], initOptions: InitOptions = InitOptions(), hooks: GlobalHooks? = nil, language: String? = nil)` | Initialize the Screeb SDK. | [Guide](https://developers.screeb.app/sdk-ios/install) |
| `closeSdk()`                                                                                                                                                                                                          | Stop the SDK.              | [Guide](https://developers.screeb.app/sdk-ios/install) |

### Identity

| Method                                                                       | Description                                                                                                                                                                                                                                                                                                                                                                                           | More                                                                             |
| ---------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `setIdentity(uniqueVisitorId: String, visitorProperty: [String: Any] = [:])` | Identify the current user with optional properties.                                                                                                                                                                                                                                                                                                                                                   | [Guide](https://developers.screeb.app/sdk-ios/identity)                          |
| `resetIdentity()`                                                            | Reset the current visitor identity.                                                                                                                                                                                                                                                                                                                                                                   | [Guide](https://developers.screeb.app/sdk-ios/identity)                          |
| `setAnonymousId(anonymousId: String)`                                        | Adopts the anonymous id your CDP already uses (Amplitude device id, Segment or RudderStack anonymous id) on the current respondent, which stays anonymous. When the CDP integration already created a respondent for that id, Screeb switches to it, unless the current respondent is identified. Call it right after `initSdk`: the command is queued and resolved during init. 5 to 128 characters. | [Guide](https://developers.screeb.app/sdk-ios/identity#2-share-one-anonymous-id) |
| `visitorProperty(visitorProperty: [String: Any])`                            | Send visitor properties without changing the identity.                                                                                                                                                                                                                                                                                                                                                | -                                                                                |
| `getIdentity(callback: @escaping ([String: Any]?, Error?) -> Void)`          | Get the current visitor identity and properties.                                                                                                                                                                                                                                                                                                                                                      | [Guide](https://developers.screeb.app/sdk-ios/identity)                          |

### Groups

| Method                                                                        | Description                           | More                                                             |
| ----------------------------------------------------------------------------- | ------------------------------------- | ---------------------------------------------------------------- |
| `assignGroup(type: String?, name: String, properties: [String: Any] = [:])`   | Assign the current user to a group.   | [Guide](https://developers.screeb.app/sdk-ios/group-assignation) |
| `unassignGroup(type: String?, name: String, properties: [String: Any] = [:])` | Remove the current user from a group. | [Guide](https://developers.screeb.app/sdk-ios/group-assignation) |

### Tracking

| Method                                                                    | Description                      | More                                                           |
| ------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------------- |
| `trackEvent(name: String, trackingEventProperties: [String: Any] = [:])`  | Track a custom event.            | [Guide](https://developers.screeb.app/sdk-ios/event-tracking)  |
| `trackScreen(name: String, trackingEventProperties: [String: Any] = [:])` | Track a screen navigation event. | [Guide](https://developers.screeb.app/sdk-ios/screen-tracking) |

### Surveys

| Method                                                                                                                                                                                                                      | Description                               | More                                                                         |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ---------------------------------------------------------------------------- |
| `startSurvey(surveyId: String, allowMultipleResponses: Bool = true, hiddenFields: [String: Any] = [:], ignoreSurveyStatus: Bool = true, hooks: SurveyHooks? = nil, language: String? = nil, distributionId: String? = nil)` | Start a specific survey programmatically. | [Guide](https://developers.screeb.app/sdk-ios/start-survey-programmatically) |
| `closeSurvey(surveyId: String? = nil)`                                                                                                                                                                                      | Close the currently displayed survey.     | -                                                                            |

### Messages

| Method                                                                                                                                                                                                                         | Description                                | More                                                                          |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | ----------------------------------------------------------------------------- |
| `startMessage(messageId: String, allowMultipleResponses: Bool = true, hiddenFields: [String: Any] = [:], ignoreMessageStatus: Bool = true, hooks: SurveyHooks? = nil, language: String? = nil, distributionId: String? = nil)` | Start a specific message programmatically. | [Guide](https://developers.screeb.app/sdk-ios/start-message-programmatically) |
| `closeMessage(messageId: String? = nil)`                                                                                                                                                                                       | Close the currently displayed message.     | [Guide](https://developers.screeb.app/sdk-ios/start-message-programmatically) |

### Session replay

| Method                 | Description                     | More                                                          |
| ---------------------- | ------------------------------- | ------------------------------------------------------------- |
| `sessionReplayStart()` | Start session replay recording. | [Guide](https://developers.screeb.app/sdk-ios/session-replay) |
| `sessionReplayStop()`  | Stop session replay recording.  | [Guide](https://developers.screeb.app/sdk-ios/session-replay) |

### Debug

| Method                                                         | Description                      | More                                                           |
| -------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------------- |
| `debug(callback: ((String?, Error?) -> Void)? = nil)`          | Get SDK debug information.       | [Guide](https://developers.screeb.app/sdk-ios/troubleshooting) |
| `debugTargeting(callback: ((String?, Error?) -> Void)? = nil)` | Get targeting debug information. | [Guide](https://developers.screeb.app/sdk-ios/troubleshooting) |

### Privacy helpers

| Method                          | Description                                              | More                                                           |
| ------------------------------- | -------------------------------------------------------- | -------------------------------------------------------------- |
| `UIView.screebMaskText()`       | Mask a view or component in session replay.              | [Guide](https://developers.screeb.app/sdk-ios/privacy-helpers) |
| `UIView.screebNoCapture()`      | Exclude a view or component from session replay capture. | [Guide](https://developers.screeb.app/sdk-ios/privacy-helpers) |
| `UIView.screebId(_ id: String)` | Set a stable Screeb element ID for IAM targeting.        | [Guide](https://developers.screeb.app/sdk-ios/privacy-helpers) |

### Other

| Method                             | Description                                                                                                                                           | More                                                     |
| ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| `handleDeepLink(url: URL?)`        | Forward a Screeb deep link to the SDK, so editor, survey and message links open in-app.                                                               | -                                                        |
| `setColorScheme(_ scheme: String)` | Sets the color scheme the surveys and messages use: "light", "dark" or "auto" (follow the app's appearance). Overrides the `colorScheme` init option. | [Guide](https://developers.screeb.app/sdk-ios/dark-mode) |

## API signatures

### Lifecycle

```swift
initSdk(context: UIViewController?, channelId: String, identity: String? = nil, visitorProperty: [String: Any] = [:], initOptions: InitOptions = InitOptions(), hooks: GlobalHooks? = nil, language: String? = nil)
closeSdk()
```

### Identity

```swift
setIdentity(uniqueVisitorId: String, visitorProperty: [String: Any] = [:])
resetIdentity()
setAnonymousId(anonymousId: String)
visitorProperty(visitorProperty: [String: Any])
getIdentity(callback: @escaping ([String: Any]?, Error?) -> Void)
```

### Groups

```swift
assignGroup(type: String?, name: String, properties: [String: Any] = [:])
unassignGroup(type: String?, name: String, properties: [String: Any] = [:])
```

### Tracking

```swift
trackEvent(name: String, trackingEventProperties: [String: Any] = [:])
trackScreen(name: String, trackingEventProperties: [String: Any] = [:])
```

### Surveys

```swift
startSurvey(surveyId: String, allowMultipleResponses: Bool = true, hiddenFields: [String: Any] = [:], ignoreSurveyStatus: Bool = true, hooks: SurveyHooks? = nil, language: String? = nil, distributionId: String? = nil)
closeSurvey(surveyId: String? = nil)
```

### Messages

```swift
startMessage(messageId: String, allowMultipleResponses: Bool = true, hiddenFields: [String: Any] = [:], ignoreMessageStatus: Bool = true, hooks: SurveyHooks? = nil, language: String? = nil, distributionId: String? = nil)
closeMessage(messageId: String? = nil)
```

### Session replay

```swift
sessionReplayStart()
sessionReplayStop()
```

### Debug

```swift
debug(callback: ((String?, Error?) -> Void)? = nil)
debugTargeting(callback: ((String?, Error?) -> Void)? = nil)
```

### Privacy helpers

```swift
UIView.screebMaskText()
UIView.screebNoCapture()
UIView.screebId(_ id: String)
```

### Other

```swift
handleDeepLink(url: URL?)
setColorScheme(_ scheme: String)
```
