Gladly
public class Gladly
Gladly is an API that allow an app to embedd Gladly chat and control it’s behaviour.
This class acts as a singleton for the Gladly instance. No more then one instance can be created at any time.
-
The Gladly SDK version
Declaration
Swift
public static let version: String
-
A delegate object for receiving notifications.
Declaration
Swift
public static var notificationDelegate: GladlyNotificationDelegate? { get set }
-
A delegate object for handling chat events
Declaration
Swift
public static var chatDisplayDelegate: GladlyChatDisplayDelegate? { get set }
-
A delegate object for handling when the unread message count changes
Declaration
Swift
public static var unreadCountDelegate: GladlyUnreadCountDelegate? { get set }
-
Initializes Gladly, this must be called before any other function is called.
Throws
GladlyError.alreadyInitialized
if Gladly has already been initializedDeclaration
Swift
public static func initialize(settings: GladlySettings) throws
Parameters
settings
This contains configuration options for Gladly.
-
isInitialized return true if the SDK has already been initialized and false if it has not yet been initialized.
Declaration
Swift
public static func isInitialized() -> Bool
Return Value
A Bool indicating if the SDK has been initialized or not.
-
Destroys the Gladly instance and frees up any memory it allocated. In order to use Gladly again, you must call initialize().
Declaration
Swift
public static func destroy()
-
Sets the current user that will be user when communicating with Gladly. If this is set the user does not have to provide email and name. If a user has previously been set, an Error will be thrown
Throws
GladlyError.userAlreadyDefined
if a user has previously been defined.Throws
GladlyError.notInitialized
if Gladly has not been initialized.Declaration
Swift
public static func set(user: GladlyUser) throws
Parameters
user
The user that Gladly will use.
-
getUser return the current user if one exist.
Throws
GladlyError.notInitialized
if Gladly has not been initialized.Declaration
Swift
public static func getUser() throws -> GladlyUser?
Return Value
GladlyUser if one exist or nil
-
Removes the currently signed in user and all data associated with that user.
Declaration
Swift
public static func logout()
-
Presents Gladly chat on top of the current view.
Throws
GladlyError.notInitialized
if Gladly has not been initialized.Declaration
Swift
public static func showChat() throws
-
Request the number of unread messages in a chat conversation.
Declaration
Swift
public static func getUnreadCount(completionHandler: @escaping (Int, GladlyError?) -> Void)
Parameters
completionHandler
callback function that will be called once the unread count has been retrieved.
-
Register deviceToken that will be used to send push notifications.
Example of usage when implementing UNUserNotificationCenterDelegate:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { do { try Gladly.register(deviceToken: deviceToken) } catch { print("failed to register token: \(error)") } }
Throws
GladlyError.notInitialized
if Gladly has not been initializedDeclaration
Swift
public static func register(deviceToken: Data) throws
Parameters
deviceToken
The deviceToken to register with Gladly.
-
Unregister device token from Gladly SDK, the result of this is that no push notifications will be sent to this device.
Throws
GladlyError.notInitialized
if Gladly has not been initializedDeclaration
Swift
public static func unregisterDeviceToken() throws
-
Call this function when a push notification is received when the app was running in the background and the user clicks on the notification. If the notification was intended for Gladly, we will present Gladly Chat over the current view.
Example of usage when implementing UNUserNotificationCenterDelegate:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { _ = Gladly.handleNotification(didReceive: response) completionHandler() }
Declaration
Swift
public static func handleNotification(didReceive response: UNNotificationResponse) -> Bool
Parameters
response
The notification response from APNS.
Return Value
A Bool indicating if the notification was addressed to Gladly.
-
Call this function when a push notification is received when the app is running in the foreground. We will not present Gladly Chat over the current view.
Example of usage when implementing UNUserNotificationCenterDelegate:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { _ = GladlySidekick.handleNotification(willPresent: notification.request) completionHandler(UNNotificationPresentationOptions(rawValue: 0)) }
Declaration
Swift
public static func handleNotification(willPresent notification: UNNotificationRequest) -> Bool
Parameters
notification
The notification request from APNS.
Return Value
A Bool indicating if the notification was addressed to Gladly.