UnbluCoreApi

@objc
open class UnbluCoreApi : NSObject

The API to use to access unblu suite functionality like showing, opening conversations

Before calling any other function #configureApi should be called inside the AppDelegate.

Use the constants of UnbluEventApi to register for events and access their user info data

A typical flow for the usage would be:

AppDelegate#application() {
   UnbluCoreApi.instance.configureApi(UnbluApiConfiguration(unbluBaseUrl: "<base-url>", apiKey: "<apiKey>"))

   //register for general errors and/or also other events
   NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.handleErrorEvent(notification:)), name: Notification.Name.UnbluError, object: nil)

   //start the api. This could also be done later when it is needed, but it will take a while until the api is ready
   UnbluCoreApi.instance.initApi(success: {<success handling>}, failure: {<error handling>})
}
SomeViewController#showConversations() {
   //the conversations should be shown
   UnbluCoreApi.instance.showUi(visible: true)
}
  • Enables the debug output of the Unblu SDK. This contains additional information on log messages and is independent of the log level defined with logLevel.

    Declaration

    Swift

    public static var enableDebugOutput: Bool
  • Enables logging of capturing performance (e.g. FPS)

    IMPORTANT: This only has effect, if enableDebugOutput is set to true and the log level is set to debug via logLevel!

    Declaration

    Swift

    public static var enableCapturingPerformanceLogging: Bool
  • Defines the log level of the Unblu SDK. All messages with a lower level will not be logged.

    Default value is LogLevel.info

    Declaration

    Swift

    public static var logLevel: LogLevel
  • Prevents the scrolling of the ui when the keyboard is shown/hidden

    This setting should only be changed, if it does create issues. If it is disabled, the user of the sdk has to take care that the ui container/the webview inside is correctly resize if needed

    Declaration

    Swift

    public static var preventScrollingByKeyboard: Bool
  • The time used for the fade in and fade out animation when showing/hiding the ui

    Declaration

    Swift

    public static let ANIMATION_TIME: TimeInterval
  • As the Unblu SDK defines an own UIWindow with a UIViewController, iOS uses this controller to define the StatusBarStyle. There is no proper way of checking for the real active UIViewController from which this value should be taken. Therefor it is required to also set the correct StatusBarStyle for the UIViewController inside the SDK.

    Declaration

    Swift

    @objc
    public dynamic var preferredStatusBarStyle: UIStatusBarStyle
  • Configures the unblu api. Use #initializeApi() to be able start new conversation and use other API features.

    Note:

    • This should only be called once with the correct configuration.
    • This method should be called from the application function of the AppDelegate class.

      • configuration: The configuration for the unblu api

      Throws

      Throws an error if the api was already initialized. The api needs to be deinitialized to configure it.

    Declaration

    Swift

    public func configureApi(configuration: UnbluApiConfiguration) throws

    Parameters

    configuration

    The configuration for the unblu api

  • Inits the unblu API.

    This is an asynchronous call. Any further calls can be done inside the success callback or after the ApiIsInitialized notification.

    Connects to the unblu server and makes the API ready for further calls.

    Consecutive calls (without deinitializing inbetween) will be ignored, but the callbacks will also be triggered, as soon as there is a result.

    Declaration

    Swift

    public func initApi(success: (() -> Void)? = nil, preloadUiFinished: (() -> Void)? = nil, failure: ((UnbluApiInitializeError) -> Void)? = nil)

    Parameters

    success

    Optional callback that will be called once the API has been successfully initialized.

    preloadUiFinished

    Optional callback that will be called once the ui is preloaded. (Preloading must be enabled)

    failure

    Optional callback that will be called if the initialization of the API fails.

  • Deinitializes the unblu API.

    This is an asynchronous call. Use the callbacks to check for success / failure.

    Calling this method will free all resources allocated by the unblu API.

    Consecutive calls (without initializing inbetween) will be ignored, but the callbacks will also be triggered, as soon as there is a result.

    Declaration

    Swift

    public func deinitApi(success: (() -> Void)? = nil, failure: ((UnbluApiDeinitializeError) -> Void)? = nil)

    Parameters

    success

    Optional callback that will be called once the API has been successfully deinitialized.

    failure

    Optional callback that will be called if the deinitialization of the API fails.

  • Returns true if the API was initialized and the initialization of the API was successful. false if api is not initialized or in error state.

    This is an asynchronous call. Use the callbacks to check for success / failure.

    Declaration

    Swift

    public func isInitialized(success: @escaping (Bool) -> Void)

    Parameters

    success

    Callback that will be called with true if the API is initialized. false otherwise.

  • Returns true if the API is in error state.

    This is an asynchronous call. Use the callbacks to check for success / failure.

    Declaration

    Swift

    public func isInErrorState(success: @escaping (Bool) -> Void)

    Parameters

    success

    Callback that will be called with true if the API is in error state. false otherwise.

  • Starts preloading the ui. Can be called as soon as the api is initialized. It will load the page, which is needed later for the ui. If enablePreloadUiAfterApiInit of #configureApi is set to true.

    Calling this function multiple times will have no effect.

    This is an asynchronous call. Use the callbacks to check for success / failure.

    Declaration

    Swift

    public func preloadUi(success: (() -> Void)? = nil, failure: ((UnbluApiNotInitializedError) -> Void)? = nil)

    Parameters

    success

    Optional callback that will be called once the preloading is finished.

    failure

    Optional callback that will be called if the api was not initialized.

  • Adds the view with the given tag to the set of private views.

    Private views are only visible on the mobile device and won’t be transmitted when co-browsing. The views will be covered before they are transmitted and therefore won’t be visible on the agent side.

    Note:

    Do not add to many tags simultaneously, because each private view will need extra performance while capturing the UI. The best practice is to dynamically make views private, when they are displayed in the app UI and remove them from the private view list when they are not visible anymore.

    Multiple calls with the same tag do not have any effect.

    Declaration

    Swift

    public func addPrivateView(withTag tag: Int)

    Parameters

    tag

    Tag of the view that should be made private.

  • Removes the view with the given tag from the set of private views.

    Multiple calls with the same tag do not have any effect.

    See: #addPrivateView

    Declaration

    Swift

    public func removePrivateView(withTag tag: Int)

    Parameters

    tag

    Tag of the view that should removed from the private views.

  • Adds a private area of the screen that will be obscured during a co-browsing session. If a private area already exists with this id, the current existing one will be updated and returned.

    Declaration

    Swift

    public func addPrivateArea(withId id: String, x: CGFloat? = nil, y: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil) -> UnbluCoBrowsingPrivateArea

    Parameters

    id

    A String id to be assigned to the private area. Use this id to update and remove later on.

    x

    The new absolute x position of the private area on the screen (optional)

    y

    The new absolute y position of the private area on the screen (optional)

    width

    The new width of the private area on the screen (optional)

    height

    The new width of the private area on the screen (optional)

    Return Value

    An instance of UnbluCoBrowsingPrivateArea.

  • Removes a private area with a given id that represents an area of the screen currently obscured during a co browsing session.

    Declaration

    Swift

    public func removePrivateArea(withId id: String)

    Parameters

    id

    A String id of a private area to remove.

  • Sets the given cookies for the configured unblu base url. This can be called independent of the state of the api. If the api was already initialized and cookies were already placed, it will overwrite cookies with the same key. Others will not be touched. All cookies will be removed when #deinitApi was called. When #initApi is called again the last cookies set will be used again.

    Declaration

    Swift

    public func setCustomCookies(_ customCookies: [String : String])

    Parameters

    customCookies

    The cookies which will be send with request to the configured base url

  • Sets or updates the named area. This can be called independent of the state of the api, but has different effects depending on the current state. If the api is not initialized when calling this function, the configuration of the named area is loaded as soon as the api gets initialized. If this function is called and the api is already initialized, it can only be used on the agent desk to filter incoming requests in the queue. No specific configuration is loaded for it. If a conversation is already active, this function has no effect until the api is either initialized again (what would load the configuration of the named area) or a new conversation is started (filtering named area in the queue).

    Declaration

    Swift

    public func setNamedArea(_ namedArea: String?)

    Parameters

    namedArea

    The named area meta tag id which is configured on the agent desk.

  • Checks if the call UI for an audio/video call is open or not. If the call Ui is minized, the result is also false. If you need to check if a call is active or not. Use the #isCallActive function.

    This is an asynchronous call. Use the callbacks to check for success / failure.

    Declaration

    Swift

    public func isCallUiOpen(success: ((Bool) -> Void)? = nil, failure: ((UnbluApiNotInitializedError) -> Void)? = nil)

    Parameters

    success

    Optional callback that will be called with the result if the UI is open or not

    failure

    Optional callback that will be called if the api was not initialized.

  • Checks if the ui is visible or not

    Declaration

    Swift

    public func isUiVisible(_ callback: @escaping (Bool) -> Void)

    Parameters

    callback

    Triggered with the result if the ui is visible or not

  • Displays are hides the unblu ui

    Declaration

    Swift

    public func showUi(visible: Bool, animate: Bool = true, success: (() -> Void)? = nil, failure: ((UnbluApiNotInitializedError) -> Void)? = nil)

    Parameters

    visible

    If set to true, the ui will be display. If set to false, it will be hidden

    animate

    If set to true, displaying/hidding the ui will be animated

    success

    Called after the ui is displayed/hidden and (if enabled) the animation has finished

    failure

    Called if the api was not initialized first

  • Set the margins of the UI. This can be used, if there should be a an open/close fab button or some menu at the top

    Declaration

    Swift

    public func setUiMargins(top uiTopMargin: CGFloat, bottom uiBottomMargin: CGFloat, animate: Bool = false)

    Parameters

    top

    The amount of margin in pixel at the top

    bottom

    The amount of margin in pixel at the bottom

    animate

    If set to true, the change of the margin is animated. Default is false

  • Opens the conversation for the given id. The unblu UI must have been visible at least once. You can call this after a call to showUi (wait for the success callback).

    Declaration

    Swift

    public func openConversation(_ conversationId: String, success: (() -> Void)? = nil, failure: ((UnbluApiOpenConversationError) -> Void)? = nil)

    Parameters

    conversationId

    The id of the conversation which should be opened.

    success

    Called after the conversation was opened

    failure

    Called if there was an error opening the conversation

  • Opens a conversation for the given conversation id and starts an audio call. The unblu UI must have been visible at least once. You can call this after a call to showUi (wait for the success callback).

    Declaration

    Swift

    public func startAudioCall(_ conversationId: String, success: (() -> Void)? = nil, failure: ((UnbluApiStartAudioCallError) -> Void)? = nil)

    Parameters

    conversationId

    The id of the conversation in which the audio call should be started

    success

    Called after the conversation was opened and the call has been started

    failure

    Called if there was an error opening the conversation and starting the call

  • Opens a conversation for the given conversation id and starts a video call. The unblu UI must have been visible at least once. You can call this after a call to showUi (wait for the success callback).

    Declaration

    Swift

    public func startVideoCall(_ conversationId: String, success: (() -> Void)? = nil, failure: ((UnbluApiStartVideoCallError) -> Void)? = nil)

    Parameters

    conversationId

    The id of the conversation in which the video call should be started.

    success

    Called after the conversation was opened and the call has been started

    failure

    Called if there was an error opening the conversation and starting the call

  • Opens the overview over all conversations. The unblu UI must have been visible at least once. You can call this after a call to showUi (wait for the success callback).

    Declaration

    Swift

    public func openConversationOverview(success: (() -> Void)? = nil, failure: ((UnbluApiOpenConversationOverviewError) -> Void)? = nil)

    Parameters

    success

    Called when the overview was opened

    failure

    Called if there was an error opening the overview

  • Returns the id of the currently opened conversation inside the UI. Null if no conversation is open

    Declaration

    Swift

    public func getOpenConversationId(success: @escaping (String?) -> Void, failure: ((UnbluApiRetrieveOpenConversationIdError) -> Void)? = nil)

    Parameters

    success

    Called with the currently open conversation id or nil

    failure

    Called if the api is not initialized or the UI was never shown

  • Returns if there is currently a call or not

    Declaration

    Swift

    public func isCallActive(success: @escaping ((Bool) -> Void), failure: ((UnbluApiNotInitializedError) -> Void)? = nil)

    Parameters

    success

    Called with the state of a call

    failure

    Called if the api was not initialized first

  • Number of unread messages

    Declaration

    Swift

    public var unreadMessagesCount: Int { get }
  • Returns the info of the current person

    Declaration

    Swift

    public func getPersonInfo(success: @escaping (PersonInfo) -> Void, failure: ((UnbluApiRetrievePersonInfoError) -> Void)? = nil)

    Parameters

    success

    Called with the current person information

    failure

    Called if the api is not initialized or the used collaboration server is not of version 5.x newer than 5.17 or newer than 6.3

  • Checks if mobile co-browsing is active

    Declaration

    Swift

    public func isMobileCoBrowsingActive(success: @escaping (Bool) -> Void, failure: ((UnbluApiIsMobileCoBrowsingActiveError) -> Void)? = nil)

    Parameters

    success

    Called with true if mobile co-browsing is active

    failure

    Called if the api is not initialized or the used collaboration server is not of version 5.x newer than 5.17 or newer than 6.3

  • Stops mobile co-browsing

    Declaration

    Swift

    public func stopMobileCoBrowsing(success: @escaping () -> Void, failure: ((UnbluApiStopMobileCoBrowsingError) -> Void)? = nil)
  • Custom loading view creator which is used whenever a loading view is displayed

    Declaration

    Swift

    public var customLoadingViewCreator: UnbluCustomLoadingViewCreator?
  • This is for internal purpose only!

    Declaration

    Swift

    public let apiDelegate: IUnbluCoreApiDelegate
  • Internal access to the controller of the unblu UI

    Declaration

    Swift

    private(set) public var uiController: UnbluUiController? { get }
  • Internal driver. Needed to access driver from Visitor/Agent SDK

    Declaration

    Swift

    public private(set) var driver: MobileDeviceDriverCoreApi? { get }
  • The currently configured bottom margin of the UI

    Declaration

    Swift

    public private(set) var uiBottomMargin: CGFloat { get }
  • The currently configured top margin of the UI

    Declaration

    Swift

    public private(set) var uiTopMargin: CGFloat { get }
  • Helper to quickly check if is initialized. Should only be called inside an main.async queue

    Declaration

    Swift

    public func isInitializedInternal() -> Bool
  • Internal constructor. Used by Agent/Visitor SDK

    Declaration

    Swift

    public init(_ apiDelegate: IUnbluCoreApiDelegate)