Documentation

SDK Functions

Here's a list of all the functions and properties supported by the UserView iOS SDK.

All methods and properties are accessed through the Upscope.shared singleton.

Connection Management

FunctionDescription
connect()Establishes a WebSocket connection to the servers.
disconnect()Closes the connection and ends any active session.
reset(reconnect: Bool = true)Resets the connection, clearing all stored identities and visitor data. Pass false to stay disconnected after reset.

Session Control

FunctionDescription
stopSession()Ends the current screen sharing session.
requestAgent()Signals that the visitor wants assistance from an agent.
cancelAgentRequest()Cancels a pending agent request.
getLookupCode()Requests a 4-digit lookup code from the server. Access the code via the lookupCode property or lookupCodePublisher.
sendCustomMessage(_ message: String)Sends a custom text or JSON message to the agent (max 5000 characters).

State Properties

PropertyTypeDescription
isConnectedBoolWhether the SDK is currently connected to the server.
isInSessionBoolWhether a screen sharing session is currently active.
connectionStateConnectionStateCurrent connection state (.inactive, .connecting, .connected, .reconnecting, .error).
sessionStateSessionStateCurrent session state (.inactive, .pendingRequest, .active, .paused, .ended).
shortIdString?The visitor's unique short ID assigned by the server.
lookupCodeString?The current 4-digit lookup code, if one has been generated.
watchLinkURL?The full URL where agents can view the session (https://upscope.com/w/{shortId}).

Visitor Identification

You can set visitor identity either through direct property assignment or as a batch update.

Direct Properties

Upscope.shared.uniqueId = "user-123"
Upscope.shared.callName = "John Smith"
Upscope.shared.tags = ["#VIP"]
Upscope.shared.identities = ["John Smith", "john@example.com"]
Upscope.shared.metadata = ["plan": "enterprise", "region": "US"]

Batch Update

Use updateConnection() to update multiple fields at once:

Upscope.shared.updateConnection(
    uniqueId: "user-123",
    callName: "John Smith",
    tags: ["#VIP"],
    identities: ["John Smith", "john@example.com"],
    metadata: ["plan": "enterprise", "region": "US"]
)

Pass nil to keep an existing value unchanged. Only non-nil parameters are updated.

Reactive State (Combine)

Subscribe to state changes using Combine publishers:

import Combine

var cancellables = Set<AnyCancellable>()

// Connection state changes
Upscope.shared.connectionStatePublisher
    .sink { state in
        print("Connection: \(state)")
    }
    .store(in: &cancellables)

// Session state changes
Upscope.shared.sessionStatePublisher
    .sink { state in
        print("Session: \(state)")
    }
    .store(in: &cancellables)

// Short ID changes
Upscope.shared.shortIdPublisher
    .sink { shortId in
        print("Short ID: \(shortId ?? "none")")
    }
    .store(in: &cancellables)

// Lookup code changes
Upscope.shared.lookupCodePublisher
    .sink { code in
        print("Lookup code: \(code ?? "none")")
    }
    .store(in: &cancellables)

Masking

Hide sensitive content from agents during screen sharing.

Property/FunctionDescription
maskSecureTextFieldsBool — Automatically mask secure text fields. Default: true.
addMaskedView(_ view: UIView)Register a UIKit view to be masked (hidden from agent).
removeMaskedView(_ view: UIView)Unregister a masked view.
allMaskedViews[UIView] — All currently masked views.

Example

// Mask a specific UIKit view
Upscope.shared.addMaskedView(creditCardField)

// Later, remove the mask
Upscope.shared.removeMaskedView(creditCardField)

// Disable automatic secure field masking
Upscope.shared.maskSecureTextFields = false