Atlas Swift SDK
Installation
CocoaPods
Add the SDK to your Podfile
:
platform :ios, '13.0'
use_frameworks!
target 'YourApp' do
pod 'AtlasSupportSDK', '~> 0.0.6'
end
Run the following command in your terminal:
pod install
Open the .xcworkspace
file in Xcode.
Usage
Import the SDK
In any file where you want to use the SDK, import it:
import AtlasSupportSDK
In this example, we import the SDK into HomeViewController and TabBarController because these are the two navigation points leading to the AtlasViewController.
Initialize and Configure the SDK
Call the appropriate initialization and configuration methods erly. Depends on your app architecture.
For example:
AtlasSDK.setAppId("YOUR_APP_ID")
You can find YOUR_APP_ID
in the Atlas application: https://app.atlas.so/settings/company
Presenting the Atlas Chat ViewController
The getAtlassViewController
method can return an optional value. This occurs if the appId is not provided, which is required for initializing the SDK correctly.
guard let atlassViewController = AtlasSDK.getAtlassViewController() else {
print("HomeViewController Error: Can not create AtlasSDK View Controller")
return
}
navigationController?.present(atlassViewController, animated: true)
User Identification
The Atlas SDK allows the chat to operate without identification. In this case, conversations are initiated without associating them with a specific customer. However, developers can link conversations to existing customer by calling the identify
method with a valid user ID.
// Identify a user before presenting the chat
AtlasSDK.identify(userId: "UNIQUE_USER_IDENTIFIER",
userHash: nil, // Required if authenication is enabled in Atlas Configuration
userName: "John Doe", // Optional
userEmail: "[email protected]") // Optional
// Proceed to present the chat
if let chatViewController = AtlasSDK.getAtlassViewController() {
navigationController?.present(chatViewController, animated: true)
}
Customization
It's possible to pass query key to a getAtlassViewController to configure the behavior or content of the returned AtlasFragment. (For ex: open specified chatbot to handle possible customer request)
Default value: "" (empty string).
Expected format: "key1: value1; key2: value2; ...."
val atlasFragment = AtlasSdk.getAtlasFragment(query = "chatbotKey: report_bug; prefer: last")
chatbotKey: KEY
Specifies the chatbot that has to be started immediately when AtlasFragment is loaded
prefer: last
Instead of starting new chatbot everytime it will open the last not completed chatbot if exists
Handling AtlasSDK Events and Delegates
The AtlasSDK provides a flexible way to handle chat events through both delegates and closures. These mechanisms allow developers to respond to various chat-related events, such as errors, ticket creation, or conversation updates, in a structured manner.
You can add event handlers by calling the following methods:
AtlasSDK.setDelegate(self) // Add a delegate conforming to `AtlasSDKDelegate`
AtlasSDK.setOnErroHandler(atlasErrorHandler) // Closure for handling errors
AtlasSDK.setStatsUpdateHandler(atlasStatsUpdateHandler) // Closure for conversation stats updates
AtlasSDK.setOnNewTicketHandler(atlasOnNewTicketHandler) // Closure for new ticket creation
Each method appends your handler or delegate to the SDK's internal storage, allowing multiple listeners to respond to the same event.
To remove a previously added delegate or closure, use the corresponding remove methods:
AtlasSDK.removeDelegate(self) // Remove delegate
AtlasSDK.removeOnErroHandler(atlasErrorHandler) // Remove error handler
AtlasSDK.removeOnNewTicketHandler(atlasOnNewTicketHandler) // Remove ticket handler
AtlasSDK.removeOnNewTicketHandler(atlasStatsUpdateHandler) // Remove stats update handler
Requirements
- iOS 13.0 or later.
- Swift 4.0 or later.
Support
For issues or feature requests, contact the engineering team at [email protected] or visit the GitHub Issues page.
For more details, visit the official Atlas Support website.
Updated 14 days ago