ConnectionProvider
public protocol ConnectionProvider : Sendable
The provider for connection related properties and methods.
-
The current channel configuration for currently connected CXone session.
Declaration
Swift
var channelConfiguration: ChannelConfiguration { get } -
Makes an HTTP request to get the channel configuration details.
The most recently fetched configuration is cached in memory for five minutes, so repeated calls for the same brand, channel and environment usually resolve without a network request, and a configuration changed in the backend can take up to that long to be reflected. Only one configuration is held at a time: a call targeting a different brand, channel or environment replaces it rather than being cached alongside it. Signing out clears the cache.
Throws
channelConfigFailureif provided parameters do not create a valid URL.Throws
sdkVersionNotSupportedif the SDK version is not supported by the server.Throws
DecodingError.dataCorruptedan indication that the data is corrupted or otherwise invalid.Throws
DecodingError.typeMismatchif the encountered stored value is not a JSON object or otherwise cannot be converted to the required type.Throws
DecodingError.keyNotFoundif the response does not have an entry for the given key.Throws
DecodingError.valueNotFoundif a response has a null value for the given key.Throws
URLError.badServerResponseif the URL Loading system received bad data from the server.Throws
NSErrorobject that indicates why the request failedDeclaration
Swift
func getChannelConfiguration(environment: Environment, brandId: Int, channelId: String) async throws -> ChannelConfigurationParameters
environmentThe CXone
Environmentused to connect. Relates to your location.brandIdThe unique id of the brand for which to open the connection.
channelIdThe unique id of the channel for the connection.
Return Value
Channel configuration details
-
getChannelConfiguration(chatURL:AsynchronousbrandId: channelId: ) Makes an HTTP request to get the channel configuration details.
The most recently fetched configuration is cached in memory for five minutes, so repeated calls for the same brand, channel and chat URL usually resolve without a network request, and a configuration changed in the backend can take up to that long to be reflected. Only one configuration is held at a time: a call targeting a different brand, channel or chat URL replaces it rather than being cached alongside it. Signing out clears the cache.
Throws
channelConfigFailureif provided parameters do not create a valid URL.Throws
sdkVersionNotSupportedif the SDK version is not supported by the server.Throws
DecodingError.dataCorruptedan indication that the data is corrupted or otherwise invalid.Throws
DecodingError.typeMismatchif the encountered stored value is not a JSON object or otherwise cannot be converted to the required type.Throws
DecodingError.keyNotFoundif the response does not have an entry for the given key.Throws
DecodingError.valueNotFoundif a response has a null value for the given key.Throws
URLError.badServerResponseif the URL Loading system received bad data from the server.Throws
NSErrorobject that indicates why the request failedDeclaration
Swift
func getChannelConfiguration(chatURL: String, brandId: Int, channelId: String) async throws -> ChannelConfigurationParameters
chatURLThe chat URL for the custom environment.
brandIdThe unique id of the brand for which to open the connection.
channelIdThe unique id of the channel for the connection.
Return Value
Channel configuration details
-
prepare(environment:AsynchronousbrandId: channelId: ) Prepares the SDK for establishing connection to the CXone service.
In order to use any
AnalyticsProvidermethods, you must first call this method.Throws
illegalChatStateif the SDK is not in the required state to trigger the method.Throws
missingParameter(_:)if connectionurlis not in correct format.Throws
channelConfigFailureif the SDK could not prepare URL for URLRequestThrows
DecodingError.dataCorruptedan indication that the data is corrupted or otherwise invalid.Throws
DecodingError.typeMismatchif the encountered stored value is not a JSON object or otherwise cannot be converted to the required type.Throws
DecodingError.keyNotFoundif the response does not have an entry for the given key.Throws
DecodingError.valueNotFoundif a response has a null value for the given key.Throws
URLError.badServerResponseif the URL Loading system received bad data from the server.Throws
NSErrorobject that indicates why the request failedThrows
EncodingError.invalidValueif a non-conforming floating-point value is encountered during encoding, and the encoding strategy is.throw.Throws
An error if any value throws an error during encoding.
Declaration
Swift
func prepare(environment: Environment, brandId: Int, channelId: String) async throwsParameters
environmentThe CXone
Environmentused to connect. Relates to your location.brandIdThe unique id of the brand for which to open the connection.
channelIdThe unique id of the channel for the connection.
-
Prepares the SDK for establishing connection to the CXone service.
In order to use any
AnalyticsProvidermethods, it is necessary to call this method before invoking any of them.Throws
illegalChatStateif the SDK is not in the required state to trigger the method.Throws
missingParameter(_:)if connectionurlis not in correct format.Throws
channelConfigFailureif the SDK could not prepare URL for URLRequestThrows
DecodingError.dataCorruptedan indication that the data is corrupted or otherwise invalid.Throws
DecodingError.typeMismatchif the encountered stored value is not a JSON object or otherwise cannot be converted to the required type.Throws
DecodingError.keyNotFoundif the response does not have an entry for the given key.Throws
DecodingError.valueNotFoundif a response has a null value for the given key.Throws
URLError.badServerResponseif the URL Loading system received bad data from the server.Throws
NSErrorobject that indicates why the request failedThrows
EncodingError.invalidValueif a non-conforming floating-point value is encountered during encoding, and the encoding strategy is.throw.Throws
An error if any value throws an error during encoding.
Declaration
Swift
func prepare(chatURL: String, socketURL: String, loggerURL: String, brandId: Int, channelId: String, tokenURL: String?) async throwsParameters
chatURLThe URL to be used for chat requests (channel config and attachment upload).
socketURLThe URL to be used for the WebSocket connection.
loggerURLThe URL to be use for internal chat logger.
brandIdThe unique id of the brand for which to open the connection.
channelIdThe unique id of the channel for the connection.
tokenURLThe URL to be used for transaction token requests. If nil, the URL will be automatically derived from chatURL.
-
connect()AsynchronousConnects to the CXone service via web socket.
This method establishes the web socket connection. Once connected, subscribe to
events()to receiveChatEventvalues (thread updates, agent typing, proactive actions, errors, etc.).Precondition
Either
prepare(environment:brandId:channelId:)orprepare(chatURL:socketURL:loggerURL:brandId:channelId:tokenURL:)method must be called before this method.Throws
illegalChatStateif the SDK is not in the required state to trigger the method.Throws
transactionTokenRequestFailed(statusCode:)if the transaction-token exchange fails.Throws
customerAssociationFailureif the SDK could not get customer identity and it may not have been set.Throws
missingAccessTokenif the customer was successfully authorized, but an access token wasn’t returned.Throws
invalidAccessTokenif the OAuth token was rejected or is missing.Throws
invalidRefreshToken(_:)if an explicit-PKCE reconnect’s refresh-grant recovery fails and no further automatic recovery is possible — the app must perform a new authorization flow.Throws
invalidDatawhen the Data object cannot be successfully converted to a valid UTF-8 stringThrows
invalidParameter(_:)if the socket endpoint URL has not been set properlyThrows
channelConfigFailureif the SDK could not prepare URL for URLRequestThrows
notConnectedif the pulse was not receivedThrows
missingVisitorIdif visitor ID is not set.Throws
missingParameter(_:)if unable to build the URL.Throws
missingParameter(_:)if unable to get cached transaction token.Throws
missingParameter(_:)ifsetAuthorizationCode(_:)orsetCodeVerifier(_:)was not called for the explicit OAuth flow.Throws
EncodingError.invalidValue(_:_:)if the given value is invalid in the current context for this format.Throws
URLError.badServerResponseif the URL Loading system received bad data from the server.Throws
NSErrorobject that indicates why the request failedDeclaration
Swift
func connect() async throws -
Disconnects from the CXone service and keeps the customer signed in.
Declaration
Swift
func disconnect() -
executeTrigger(_:Asynchronous) Manually executes a trigger that was defined in CXone. This can be used to test that proactive actions are displaying.
Throws
illegalChatStateif the SDK is not in the required state to trigger the method.Throws
notConnectedif an attempt was made to use a method without connecting first. Make sure you call theconnectmethod first.Throws
customerVisitorAssociationFailureif the customer could not be associated with a visitor.Throws
customerAssociationFailureThe SDK instance could not get customer identity possibly because it may not have been set.Throws
invalidDatawhen the Data object cannot be successfully converted to a valid UTF-8 stringThrows
EncodingError.invalidValue(_:_:)if the given value is invalid in the current context for this format.Throws
An error if any value throws an error during encoding.
Declaration
Swift
func executeTrigger(_ triggerId: String) async throwsParameters
triggerIdThe id of the trigger to manually execute.
View on GitHub