ChatboxController
@objc
public final class ChatboxController : NSObject
An object that controls the chatbox, which is where the conversation is displayed, and the chat button.
-
A Boolean value that determines whether the default iAdvize SDK chat button is used.
When the active targeting rule is available, a chat button is displayed to invite the user to chat. To let the SDK manage and display its default chat button, set this value to
true
. To use a custom chat button instead, set this value tofalse
.The default value is
true
.Declaration
Swift
@objc public var useDefaultFloatingButton: Bool { get set }
-
The object notified of events related to the conversation such as new messages received.
Declaration
Swift
@objc public weak var delegate: ChatboxControllerDelegate?
-
Configure the chatbox by setting some appearance properties (e.g.: the main color).
You should setup the configuration before you display the chat button or the chatbox for the first time.
Declaration
Swift
public func setupChatbox(configuration: ChatboxConfiguration)
Parameters
configuration
A struct that you can pass to override the default appearance of the chatbox.
-
Set the chat button (the default one) position. Use this method if you use the iAdvize default chat button by setting the
useDefaultFloatingButton
totrue
.We use autolayout constraints to place the chat button in the designated view (the main window by default) and to move it.
The default chat button is aligned to the bottom-left of the screen with a default margin to (left: 10, bottom: 10). Increasing the bottom margin value will move the chat button up and increasing the left margin value will move the chat button left.
Container view (default = main window) +----------------------------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | notificationButtonView | leftMargin = 10 +----+ | <------> | | | | | | | | +--^-+ | | | | | | bottomMargin = 10 | +------------v---------------------+
Declaration
Swift
@MainActor @objc public func setFloatingButtonPosition(leftMargin: Double, bottomMargin: Double)
Parameters
leftMargin
Left margin between the left edge of the chat button view and the trailing edge of its container view (default = main window). Increase it to move the button left.
bottomMargin
Bottom margin between the bottom edge of the chat button view and the bottom edge of its container view (default = main window). Increase it to move the button up.
-
Manually present the chatbox as a modal view controller.
If you use the default chat button, the iAdvize SDK automatically takes care of presenting the chatbox when the user taps on it. But if you use a custom chat button, you can use this method to present the chatbox when the button is tapped.
By default, the chatbox will be presented by the key window root view controller. If you specify a
presentingViewController
, it will be used to present the chatbox.Declaration
Swift
@objc public func presentChatbox(animated: Bool = true, presentingViewController: UIViewController? = nil, completion: (() -> Void)? = nil)
Parameters
animated
Pass
true
to animate the transition.presentingViewController
The controller that will perform the presentation.
completion
The block to execute after the presentation finishes.
-
Manually dismiss the chatbox.
The visitor can dismiss the chatbox themselves by touching the dedicated button in the navigation bar.
You can use this method to manually dismiss the chatbox.
Declaration
Swift
@objc public func dismissChatbox(animated: Bool = true, completion: (() -> Void)? = nil)
Parameters
animated
Pass
true
to animate the transition.completion
The block to execute after the chatbox is dismissed.
-
Return
true
if the chatbox is currently presented.Declaration
Swift
@MainActor @objc public func isChatboxPresented() -> Bool