iOS In-App Messaging (Modular)

The In-Appmessaging module offers both one-way and two-way messaging capabilities for your app.

Overview

The In-App Messaging module offers both one-way and two-way messaging capabilities for your app.

Classes

Class NamesDescription
InAppMessagingProviderInAppMessagingProvider is a class that provides a singleton instance of InAppMessaging. This class includes a static instance property that returns a single instance of InAppMessaging.
DefaultMessageStoreThe DefaultMessageStore class provides a default implementation of the MessageStore protocol. This class manages the storage, retrieval, and deletion of InAppMessage and InAppThread instances
InAppThreadRepresents a conversation or announcement thread.
InAppMessageRepresents a message in the WebexConnect platform.
InAppAttachmentA class that represents an attachment in an in-app message, such as an image, video, audio, location or template.
InAppMediaAttachmentRepresents a file attachment.
InAppImageAttachmentA class that represents an image attachment within an in-app message.
InAppAudioAttachmentA class that represents an audio attachment within an in-app message.
InAppVideoAttachmentA class that represents a video attachment within an in-app message.
InAppLocationAttachmentRepresents a location attachment.
InAppTemplateAttachmentA class that represents an attachment specific to a template in an in-app message.
InAppFormTemplateAttachmentA class that represents a template attachment specific to a form in an in-app message.
InAppButtonRepresents a button in an in-app message.
InAppFormFieldA class that represents a form field within an in-app form.
InAppGenericTemplateAttachmentA class that represents a specific type of template attachment for a generic template in an in-app message.
InAppGenericTemplateElementRepresents an element of a generic template.
InAppInteractiveDataRepresents interactive data.
InAppQuickReplyRepresents quick reply data attached to an in-app message.
MessageSynchronizationPolicyClass representing the policy for message synchronization. This policy determines how messages are synchronized based on the mode, and limits the number of threads and messages per thread that are synchronized.

Protocols

ProtocolsDescription
InAppMessagingA protocol that defines the requirements for in-app messaging functionalities.
InAppMessagingDelegateProtocol for receiving messaging events in the InAppConnect platform.
MediaFileManagerMediaFileManager is a protocol that defines an interface for managing media within an application. It provides methods to upload, download, and check the status of media files.
MessageStoreThe MessageStore protocol defines a methods for managing and interacting with In-App Messages and Threads in a local storage system.

Enumerations

EnumsDescription
ConnectionStatusEnum representing the connection status of the In-App Messaging connection.
InAppFormFieldTypeEnum representing different types of form field.
InAppInteractiveDataTypeEnum representing different types of interactive data.
InAppMessageStatusRepresents the status of a message.
InAppMessageTypeRepresents the type of a message.
InAppTemplateType
InAppThreadStatusRepresents the different status of a in-app thread.
InAppThreadTypeRepresents the type of a thread.
MessageSynchronizationModeEnum representing the synchronization mode for messages.

InAppMessagingProvider   

InAppMessagingProvider is a class that provides a singleton instance of InAppMessaging. This class includes a static instance property that returns a single instance of InAppMessaging. 

Properties:

PropertyTypeDescription
instance InAppMessagingThe singleton instance of InAppMessaging.

DefaultMessageStore

The DefaultMessageStore class provides a default implementation of the MessageStore protocol. This class manages the storage, retrieval, and deletion of InAppMessage and InAppThread instances.

Methods

init(password:)

This method initializes the DefaultMessageStore with given password.

Syntax: init(password: String)

Parameters

ParameterTypeDescription
password StringSpecifies a password to secure the database.

Sample Code

let messageStore = DefaultMessageStore(password: "DefaultMessageStore") 
InAppMessagingProvider.instance.messageStore = messageStore 
InAppMessagingProvider *inApp = [InAppMessagingProvider instance]; 
DefaultMessageStore *messageStore = [[DefaultMessageStore alloc] initWithPassword:@"DefaultMessageStore"]; 
[inApp setMessageStore:messageStore]; 

deleteAll()

This method deletes complete InAppThreads & InAppMessages.

Syntax: func deleteAll() -> Bool

Return Value: Returns true if deletion completes, false otherwise.

Sample Code

let hasDeleted = InAppMessagingProvider.instance.messageStore?.deleteAll()
BOOL hasDeleted = [[InAppMessagingProvider instance].messageStore deleteAll];

deleteMessage(withTransactionId:)

This method deletes single InAppMessage from local storage based on transactionId.

Syntax: func deleteMessage(withTransactionId transactionId: String) -> Bool

Return Value: Returns true if delete message completes, false otherwise.

Parameters

ParameterTypeDescription
transactionId StringThe transactionId to be deleted from local storage.

Sample Code

let hasDeleted = InAppMessagingProvider.instance.messageStore?.deleteMessage(withTransactionId: "transactionid")
BOOL hasDeleted = \[[InAppMessagingProvider instance].messageStore deleteMessageWithTransactionId:@"transactionid"];

deleteThread(withThreadId:)

This method allows us to delete single InAppThread from local storage based on threadId

Syntax: func deleteThread(withThreadId threadId: String) -> Bool

Return Value: Returns true if delete thread completes, false otherwise.

Parameters

ParameterTypeDescription
threadId StringThe threadId to be deleted from local storage.

Sample Code

let hasDeleted = InAppMessagingProvider.instance.messageStore?.deleteThread(withThreadId: "threadid")
BOOL hasDeleted = [[InAppMessagingProvider instance].messageStore deleteThreadWithThreadId:@"threadid"];

getMessageCount(forThreadId:)

This method provides a count of messages from local storage based on threadId.

Syntax: func getMessageCount(forThreadId threadId: String) -> Int

Return Value: Returns count of messages.

Parameters

ParameterTypeDescription
threadId StringThe threadId to be fetched count from local storage

Sample Code

let count = InAppMessagingProvider.instance.messageStore?.getMessageCount(forThreadId: "threadid")
int count = [[InAppMessagingProvider instance].messageStore getMessageCountForThreadId:@"threadid"];

getThreadCount()

This method provides the total number of threads count from local storage.

Syntax: func getThreadCount() -> Int

Return Value: Returns count of threads.

Sample Code

let count = InAppMessagingProvider.instance.messageStore?.getThreadCount()
int count = [[InAppMessagingProvider instance].messageStore getThreadCount];

getUnreadMessageCount(forThreadId:)

This method provides a count of unread messages from local storage based on threadId.

Syntax: func getUnreadMessageCount(forThreadId threadId: String) -> Int

Return Value: Returns count of unread messages.

Parameters

ParameterTypeDescription
threadId StringThe thread ID to retrieve the unread message count for.

Sample Code

let count = InAppMessagingProvider.instance.messageStore?.getUnreadMessageCount(forThreadId: "threadid")
int count = [[InAppMessagingProvider instance].messageStore getUnreadMessageCountForThreadId:@"threadid"];

getUnreadThreadCount()

This method gives the total number of threads containing unread messages.

Syntax: func getUnreadThreadCount() -> Int

Return Value: The number of threads containing unread messages.

Sample Code

let count = InAppMessagingProvider.instance.messageStore.getUnreadThreadCount()
int count = [[InAppMessagingProvider instance].messageStore getUnreadThreadCount];

loadMessage(withTransactionId: )

This method loads single InAppMessage from local storage based on transactionId.

Syntax: func loadMessage(withTransactionId transactionId: String) -> InAppMessage?

Return Value: Returns InAppMessage instance if message exists with transactionId.

Parameter

ParameterTypeDescription
transactionId StringThe transactionId to be retrieved from local storage

Sample Code

let inApp = InAppMessagingProvider.instance
let message = inApp.messageStore?.loadMessage(withTransactionId: "transactionid") 
InAppMessage *message = [[InAppMessagingProvider instance].messageStore loadMessageWithTransactionId:@"transactionid"];

loadMessages(withThreadId: submittedBefore: limit:)

This method loads messages from local storage for a specific thread, based on the date submittedBefore, with the specified limit.

Syntax: func loadMessages(withThreadId threadId: String, submittedBefore: Date, limit: Int) -> [InAppMessage]

Return Value: Array of InAppMessage instance if messages exists with threadId.

Parameter

ParameterTypeDescription
threadId StringThe threadId to be retrieved from local storage
 submittedBefore DateThe submittedBefore to be used to fetch messages before submittedBefore from local storage.
 limit IntThe limit to be used to fetch limited number of messages from local storage

Sample Code

let inApp = InAppMessagingProvider.instance
let submittedBefore = Date() 
let limit = 10
let messages = inApp.messageStore?.loadMessages(withThreadId: "threadid", submittedBefore: submittedBefore, limit: limit)
NSDate *submittedBefore = [NSDate new]; 
int limit = 10;
NSArray *messages = [[InAppMessagingProvider instance].messageStore loadMessagesWithThreadId:@"threadid" submittedBefore:submittedBefore limit:limit];

loadMessages(withThreadId:  submittedBefore:  submittedAfter: limit:)

This method loads messages from local storage for a specific thread, based on optional date parameters submittedBefore and submittedAfter, with the specified limit.

Syntax: func loadMessages(withThreadId threadId: String, submittedBefore: Date?, submittedAfter: Date?, limit: Int) -> [InAppMessage]

Return Value: Array of InAppMessage instance if messages exists with threadId.

Parameters

ParameterTypeDescription
threadId StringThe threadId to be retrieved from local storage.
 submittedBefore DateThe submittedBefore to be used to fetch messages before submittedBefore from local storage.
 submittedAfter DateThe submittedAfter to be used to fetch messages after submittedAfter from local storage.
 limit IntThe limit to be used to fetch limited number of messages from local storage

Sample Code

let submittedBefore = Date() // Provide your submitted Before date 
let submittedAfter = Date() // Provide your submitted After date 
let limit = 10 // provide your limit 
let messages = inApp.messageStore?.loadMessages(withThreadId: "threadid", submittedBefore: submittedBefore, submittedAfter: submittedAfter, 
limit: limit)
NSDate *submittedBefore = [NSDate new]; // Provide your submitted Before date 
NSDate *submittedAfter = [NSDate new]; // Provide your submitted After date 
int limit = 10; // provide your limit 
NSArray *messages = [[InAppMessagingProvider instance].messageStore loadMessagesWithThreadId:@"threadid" submittedBefore:submittedBefore submittedAfter:submittedAfter 
limit:limit];

loadThread(withThreadId:)

This method loads a specific InAppThread from local storage based on the provided threadId.

Syntax: func loadThread(withThreadId threadId: String) -> InAppThread?

Return Value: Returns  InAppThread instance if thread exists with threadId.

Parameters

ParameterTypeDescription
threadId StringThe threadId to be retrieved from local storage

Sample Code

let inApp = InAppMessagingProvider.instance 
let thread = inApp.messageStore?.loadThread(withThreadId: "threadid")
InAppThread *thread = [[InAppMessagingProvider instance].messageStore loadThreadWithThreadId:"threadid"];

loadThreads(updatedBefore: limit:)

This method Loads InAppThreads from local storage based date updatedBefore with the specific limit.

Syntax: func loadThreads(updatedBefore: Date, limit: Int) -> [InAppThread]

Return Value: Returns array of InAppThread instances, if threads exists before updated date with limit.

Parameters

ParameterTypeDescription
updatedBefore DateThe updatedBefore to be used to fetch threads modified before from local storage
 limit IntThe limit to be used to fetch limited number of threads from local storage

Sample Code

let inApp = InAppMessagingProvider.instance
let updatedBefore = Date()  
let limit = 10
let threads = inApp.messageStore?.loadThreads(updatedBefore: updatedBefore, limit: limit)
NSDate *updatedBefore = [NSDate new]; // Provide your updated Before date 
int limit = 10; // provide your limit 
NSArray *threads = [[InAppMessagingProvider instance].messageStore loadThreadsWithUpdatedBefore:updatedBefore limit:limit];

loadThreads(updatedBefore:  updatedAfter:  limit:)

This method loads InAppThreads from local storage based on the dates updatedBefore and updatedAfter, with the specified limit.

Syntax: func loadThreads(updatedBefore: Date, updatedAfter: Date, limit: Int) -> [InAppThread]

Return Value: Returns array of InAppThread instances, if threads exists between before & after updated date with limit.

Parameters

ParameterTypeDescription
updatedBefore DateThe updatedBefore to be used to fetch threads modified before from local storage.
 updatedAfter DateThe updatedAfter to be used to fetch threads modified after from local storage.
 limit IntThe limit to be used to fetch limited number of threads from local storage.

Sample Code

let updatedBefore = Date() // Provide your updated Before date 
let updatedAfter = Date() // Provide your updated After date 
let limit = 10 // provide your limit 
let threads = inApp.messageStore?.loadThreads(updatedBefore: updatedBefore, updatedAfter: updatedAfter, limit: limit)
NSDate *updatedBefore = [NSDate new]; // Provide your updated Before date 
NSDate *updatedAfter = [NSDate new]; // Provide your updated After date 
int limit = 10; // provide your limit 
NSArray *threads = [[InAppMessagingProvider instance].messageStore loadThreadsWithUpdatedBefore:updatedBefore updatedAfter:updatedAfter limit:limit];

loadUnreadThreads(limit:)

This method loads some InAppThread instance containing at least one unread message from local storage with specific limit.

Syntax: func loadUnreadThreads(limit: Int) -> [InAppThread]

Return Value: An array of InAppThread instances with some unread messages.

Parameters

ParameterTypeDescription
 limit IntThe limit to be used to fetch limited number of threads from local storage

Sample Code

let limit = 10 // provide your limit 
let threads = inApp.messageStore?.loadUnreadThreads(limit: limit)
int limit = 10; // provide your limit 
NSArray *threads = [[InAppMessagingProvider instance].messageStore loadUnreadThreadsWithLimit:limit];

saveMessages()

This method saves multiple InAppMessages.

Syntax: func saveMessages(_ messages: [InAppMessage]) -> Bool

Return Value: Returns true if message storage completes, false otherwise.

Parameters

ParameterTypeDescription
InAppMessageArrayThe array of InAppMessages to be saved.

Sample Code

let messages: [InAppMessage] = [] // provide ur InAppMessages 
let hasSaved = inApp.messageStore?.saveMessages(messages)
NSArray *messages = @\[]; // Provide your messages 
BOOL hasSaved = [[InAppMessagingProvider instance].messageStore saveMessages:messages]; 
Remove this function from the documentation

saveThreads()

This method saves multiple InAppThreads.

Syntax: func saveThreads(_ threads: [InAppThread]) -> Bool

Return value: Return true if thread storage completes, false otherwise.

Parameters

ParameterTypeDescription
InAppThreadArrayThe array of InAppThreads to be saved.

Sample Code

let threads: [InAppThread] = [] // provide ur InAppThreads 
let hasSaved = inApp.messageStore?.saveThreads(threads)
NSArray \*threads = @\[]; // Provide your threads 
BOOL hasSaved = \[[InAppMessagingProvider instance].messageStore saveThreads:threads];

InAppAttachment

A class that represents an attachment in an in-app message, such as an image, video, audio, location or template. 

Properties

PropertyTypeDescription
contentType StringThe content type of the attachment, such as image, video, audio, or location

The InAppAttachment class is inherited by the following subclasses: 

inherited
InAppLocationAttachment
InAppMediaAttachment
InAppTemplateAttachment

InAppAudioAttachment 

A class that represents an audio attachment within an inapp message. 

Properties

PropertyTypeDescription
duration IntThe duration of the audio attachment in seconds.

The InAppAudioAttachment class is inherited from the following superclass:

inherited
InAppMediaAttachment

Methods

init() 

Initializes a InAppAudioAttachment. 

Syntax init()


InAppButton 

This class represents a button in an in-app message.  This class exposes the data related to interactive button in quick replies and generic templates.

Properties

PropertyTypeDescription
actionURLString?The URL that can be used to open web links and deep links.
 id StringThe identifier of the button.
imageURLString?The image URL that can be used to render the image of the button.
payload[String : Any]?The payload of the button.
titleString?The title of the button.
typeInAppInteractiveDataTypeThe type of the button.

InAppFormField

A class that represents a form field within an in-app form. 

Properties

PropertyTypeDescription
dropdownOptions[String]?The options available for a dropdown field.
fieldDescriptionStringThe description of the form field.
labelStringThe label of the form field.
nameStringThe name of the form field.
fieldValueString?The value of the form field.
fieldValues[String]?The values of the form field for multi-select fields.
typeInAppFormFieldTypeThe type of the form field.
isMandatoryBoolA boolean value indicating whether the form field is mandatory.

InAppFormTemplateAttachment 

A class that represents a template attachment specific to a form in an in-app message. 

Properties

PropertyTypeDescription
formFields:[InAppFormField]An array of form fields that make up the form.
formTitleString?The title of the form.

  The InAppFormTemplateAttachment class is inherited from the following superclass:

inherited from
InAppTemplateAttachment

InAppGenericTemplateAttachment 

A class that represents a specific type of template attachment for a generic template in an in-app message. 

Properties

PropertyDescription
var elements: [InAppGenericTemplateElement]?An array of elements that are part of the generic template attachment.

The InAppGenericTemplateAttachment class is inherited by the following subclass: 

inherited by
InAppTemplateAttachment

InAppGenericTemplateElement 

Represents an element of a generic template. 

Properties

PropertyTypeDescription
buttons[InAppButton]The buttons of the generic template element.
imageURLs[String]The image URLs of the generic template element.
subTitleString?The subtitle of the generic template element.
titleString?The title of the generic template element.

The InAppGenericTemplateAttachment class is inherited from the following superclass:

inherited by
InAppTemplateAttachment

InAppImageAttachment

A class that represents an image attachment within an in-app message.

Properties

PropertyTypeDescription
previewUIImage?A preview of the image attachment.

The InAppImageAttachment class is inherited from the following superclass:

inherited by
InAppMediaAttachment

Methods

Syntax: init()
Initializes a InAppImageAttachment. 


InAppInteractiveData 

This class exposes the data related to the form response submitted by users.

Properties

PropertyTypeDescription
actionURLString?The action URL that can be used to render the image of the interactive button.
 identifierString?The identifier of the interactive data.
payload[String : Any]?The interactive data payload.
reference String?The theme/subject of the interactive button.
relatedTransactionIdString?The transaction ID for form data response.
submittedAtDate?The date when the data has been submitted.
titleString?The title of the interactive button.
typeInAppInteractiveDataTypeThe type of the interactive data.

Methods 

init() 

Initializes a InAppInteractiveData.

Syntax: init() 


InAppLocationAttachment 

Represents location data that may be attached to a message. Location data is comprised of latitude and longitude.

Properties

PropertyTypeDescription
latitude DoubleThe latitude of the location.
longitude DoubleThe longitude of the location.

The InAppLocationAttachment class is inherited from the following superclass:

inherited by
InAppAttachment

Methods 

init() 

Initializes a InAppLocationAttachment.

Syntax: init() 


InAppMediaAttachment 

Base class for message attachments which exposes data common to all types of the media files.

Properties

PropertyDescription
mediaIdString?The ID of the media attachment.
sizeIntThe size of the attachment.
urlURL?The URL of the attachment.

The InAppMediaAttachment class is inherited by the following subclass: 

inherited by
InAppAudioAttachment
InAppImageAttachment
InAppVideoAttachment

Methods 

init() 

Initializes a InAppMediaAttachment.

Syntax: init()


InAppMessage 

Represents a message in the WebexConnect platform. 

Properties

PropertyTypeDescription
attachments[InAppAttachment]?Any attachments which are or have to be attached to the message.
createdAtDate?The date when the message has been created.
customTags[String : Any]?Any custom, developer specified, data that was sent or to be sent as part of the message payload.
deliveredAtDate?The date when the message has been delivered.
deviceIdString?The device identifier associated with the message.
 extras[String : Any]?Any supplementary data that was sent as part of the message payload.
interactiveData InAppInteractiveData?The interactive data of form response.
isOutgoing BoolInforms if the message is an outgoing message.
messageString?The content of the message. Usually this is the text that is displayed to end users.
quickReplyInAppQuickReply?The quick reply data that have been attached to the message.
readAtDate?The date when the message has been read.
 relatedTransactionIdString?The TransactionId related to the Form Response.
statusInAppMessageStatusThe message status.
submittedAtDate?The date when the message has been submitted.
transactionIdString?Identifies the message transaction within the Webex Connect platform.
typeInAppMessageTypeThe type of the message.
userIdString?The userId of the message.
appIdString?The application ID of the message.

Methods 

init() 

Initializes an empty instance of InAppMessage.

Syntax: init() 


InAppQuickReply

Represents quick reply data attached to an in-app message. 

Properties

PropertyTypeDescription
buttons[InAppButton]The quick replies attached to the message.
reference StringThe reference of the quick reply data.

InAppTemplateAttachment 

A class that represents an attachment specific to a template in an in-app message. 

Properties

PropertyTypeDescription
referenceString?The reference of the template.
idString?The ID of the template.
typeInAppTemplateTypeThe type of the template.

The InAppTemplateAttachment class is inherited from the following superclass:

inherited from
InAppAttachment
inherited by
InAppFormTemplateAttachment
InAppGenericTemplateAttachment

InAppThread

Represents a conversation or announcement thread.

Properties

PropertyTypeDescription
category String?The category of the thread.
createdAt Date?The creation date of the thread.
 externalId String?The external ID of the thread.
extras[String : Any]?Additional extras associated with the thread.
reasonForStatusChangeString?The reason for the status change of the thread.
status InAppThreadStatusThe status of the thread.
idString?The thread ID.
title: String?The thread title.
type InAppThreadTypeThe type of the thread.
unreadMessageCount IntThe unread message count in the thread.
updatedAtDate?The update date of the thread.
notifyUrlString?The notify url when a new message is received.

Methods 

init() 

Initializes an empty instance of InAppThread.

Syntax: init()


InAppVideoAttachment

 A class that represents a video attachment within an in-app message. 

Properties

PropertyDescription
duration IntThe duration of the video attachment in seconds.
previewUIImage?A preview of the video attachment.

The InAppVideoAttachment class is inherited from the following superclass:

inherited by
InAppMediaAttachment

Methods 

init() 

Initializes an instance of  InAppVideoAttachment.

Syntax: init()


MessageSynchronizationPolicy 

Class representing the policy for message synchronization. This policy determines how messages are synchronized based on the mode, and limits the number of threads and messages per thread that are synchronized. 

Methods

init(mode: maxThreads: maxMessagesPerThread)

Instantiates a new Synchronization policy.

Syntax:init(mode: MessageSynchronizationMode, maxThreads: Int, maxMessagesPerThread: Int)

Properties: 

PropertyTtypeDescription
maxMessagesPerThread IntThe maximum number of messages that will be synchronized per thread.
maxThreads IntThe maximum number of threads that will be synchronized at once.
 mode MessageSynchronizationModeThe synchronization mode that will be used to synchronize messages

InAppMessaging 

A protocol that defines the requirements for in-app messaging functionalities.

Properties

PropertyTypeDescription
connectionStatus ConnectionStatusThe current connection status between the SDK and the Connect platform.
var delegateInAppMessagingDelegate?Delegate responsible for handling in-app messaging events.
isConnected BoolIndicates whether the InApp connection is currently connected.
mediaFileManager MediaFileManagerThe manager responsible for handling media-related tasks within messages. It provides methods to upload, download, and check the status of media files.
messageStoreMessageStore?The message store for the messaging service
messageSynchronizationPolicyMessageSynchronizationPolicy?The policy used to determine how messages are synchronized.

Methods  

connect()

Once the In-App Message feature is enabled in the app asset created on Webex Connect and user registration is done, the App Developer can establish a connection between the app and Webex Connect platform by calling the connect method appropriately. This enables the messages sent from Webex Connect to be received on the app. When the application is running in the background, SDK is disconnected from Webex Connect. While in the disconnected state, incoming In-App Messages are not received, however when the application comes to foreground again, SDK will establish a connection with the Webex Connect platform and allow messages to be received.

The connect method is used to establish a connection to receive In-App Messages from the Webex Connect platform. When the connection is successful, the status events are notified through InAppMessagingDelegate didChangeConnectionStatus.

It throws an error as defined if the user is not currently registered to the Webex Connect or if In-App Messaging feature is not enabled in the policy.

Syntax func connect() throws 

 Throws An error if the connection cannot be established. 

Sample Code

func connect() throws {    
var inApp = InAppMessagingProvider.instance    
try inApp.connect(
} 
(void)connect:(NSError **)error {  
id<InAppMessaging> inApp = [InAppMessagingProvider instance];  
[inApp connect:error];  
} 

createPostbackMessage(with:button:)

Creates an instance of an InAppMessage based on InAppButton and Thread 

Syntax: func createPostbackMessage(with message: InAppMessage, button: InAppButton) -> InAppMessage 

Return Value An instance of InAppMessage 

Parameters  

ParameterTypeDescription
messageInAppMessageThe InAppMessage instance
buttonInAppButtonThe interacted InAppButton for which an InAppMessage is created

 Sample Code

let inApp = InAppMessagingProvider.instance
let message = InAppMessage()
let button = InAppButton()
let postBackMessage = inApp.createPostbackMessage(with message: message, button: button)
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
InAppMessage *message = [[InAppMessage alloc] init]    
InAppButton *button = [[InAppButton alloc] init]    
InAppMessage *postBackMessage = [inApp createPostbackMessageWith message:message, button: button];  

createThread(_: completionHandler:) 

This method creates a new thread on the messaging service. 

Syntax func createThread(_ thread: InAppThread, completionHandler: @escaping (InAppThread?, Error?) -> Void) 
Parameters  

ParameterTypeDescription
threadInAppThreadThe thread to be created.
completionHandler@escaping (InAppThread?, Error?)A closure to be executed when the operation completes.

Sample Code 

let inApp = InAppMessagingProvider.instance
inApp.createThread(thread) { createdThread, error in
  //Handle Error
}
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
[inApp createThread:thread completion:^(InAppThread _createdThread, NSError *error) {    
if (error) {    
   NSLog(@"Error creating thread: %@", error.localizedDescription);    
} else {    
   NSLog(@"Successfully created thread: %@", createdThread);
}    
}]; 


deleteMessage(withTransactionId: completionHandler: ) 

This method is used to deletes a message with the specified transactionId from the messaging service.

Syntax:func deleteMessage(withTransactionId tid: String, completionHandler: @escaping (Error?) -> Void) 

Parameters  

ParameterTypeDescription
tidStringThe ID of the message to delete.
completionHandler@escaping (Error?)A closure to be executed when the operation completes.

 Sample Code 

let inApp = InAppMessagingProvider.instance  
inApp.deleteMessage(withTransactionId tid: "transaction_id") { error in
} 
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
[inApp deleteMessageWithTransactionId:"transactionid" completion:^(NSError *error) {    
   if (error) {    
       // Handle error    
       NSLog(@"Error deleting message: %@", error.localizedDescription);    
  } else {    
       // Handle success    
       NSLog(@"Message deleted successfully");    
   }    
}]; 

disconnect() 

This method is used to disconnect the connection between the app and the Webex Connect platform. If there is no active connection, then this method fails silently. When the disconnection is successful, the status events are notified through InAppMessagingDelegate didChangeConnectionStatus.

It throws an error as defined if the user is not currently registered with Webex Connect or if In-App Messaging feature is not enabled in the policy.

Syntax: func disconnect() throws 

Throws:  An error if the disconnection fails. 

Sample Code

func disconnect() throws {
  let inApp = InAppMessagingProvider.instance
  try inApp.disconnect()
}
-(void)disconnect:(NSError **error) {    
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
 [inApp disconnect:error];    
}

fetchMessages(forThreadId: beforeDate: limit: completionHandler:) 

This method fetches messages for a specific thread that are submitted before a given date, with a specified limit, and executes a completion handler upon completion.

Syntax:  func fetchMessages(forThreadId threadId: String, beforeDate: Date, limit: Int, completionHandler: @escaping ([InAppMessage], Bool, Error?) -> Void) 

 Parameters  

ParameterTypeDescription
threadIdStringThe ID of the thread to fetch messages from.
beforeDateDateThe date indicating messages before which should be fetched.
limitIntThe maximum number of messages to fetch.
completionHandler@escaping ([InAppMessage], Bool, Error?)A closure to be executed when the operation completes.

Sample Code

let inApp = InAppMessagingProvider.instance
inApp.fetchMessages(forThreadId threadId: "thread_id", beforeDate: Date(), limit: 10) { messages, hasMore, error in
                                                                                      }
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
[inApp fetchMessagesForThreadId:@ "thread_id", beforeDate: beforeDate, limit:10 completion:^(NSArray *messages, BOOL hasMore, NSError *error) {
}]; 

fetchThread(forThreadId: completionHandler:)

This method fetches a specific thread based on the provided thread ID and executes a completion handler upon completion.

 Syntax func fetchThread(forThreadId threadID: String, completionHandler: @escaping (InAppThread?, Error?) -> Void)

 Parameters  

ParameterTypeDescription
threadIdStringThe threadID of the thread.
completionHandler@escaping (InAppThread?, Error?)A completion handler called when the response is received. It will contain a thread or an error if the request failed.

Sample Code

let inApp = InAppMessagingProvider.instance
inApp.fetchThread(forThreadId: "thread_id") { (thread, error) in
  //Handle response
}
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
[inApp fetchThreadForThreadId:@"thread_id" completionHandler:^(InAppThread *thread, NSError *error) {    
//Handle response 
}]; 

fetchThreads(beforeDate:  limit: category: completionHandler:) 

This method fetches a list of threads that were updated before a given date, with a specified limit, optionally filtered by category, and executes a completion handler upon completion.

Syntax func fetchThreads(beforeDate: Date, limit: Int, category: String?, completionHandler: @escaping ([InAppThread], Bool, Error?) -> Void) 

Parameters  

ParameterTypeDescription
beforeDateDateThe date indicating threads before which should be fetched.
limitIntThe maximum number of threads to fetch.
categoryStringThe category of threads to fetch.
completionHandler@escaping ([InAppThread], Bool, Error?)A closure to be executed when the operation completes.

 Sample Code

let inApp = InAppMessagingProvider.instance
inApp.fetchThreads(beforeDate: Date(), limit: 10, category: nil) { threads, hasMore, error in
  //Handle Response
}
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
NSDate _beforeDate = [NSDate date];    
[inApp fetchThreadsBeforeDate:beforeDate limit:10 category:nil  completionHandler:^(NSArray *threads, BOOL hasMore, NSError *error) {    
//Handle response 
}]; 

fetchThreads(beforeDate: limit:  category: threadType: completionHandler:)

This method fetches a list of threads that were updated before a given date, with a specified limit, optionally filtered by category and thread type, and executes a completion handler upon completion.

Syntax: func fetchThreads(beforeDate: Date, limit: Int, category: String?, threadType: InAppThreadType, completionHandler: @escaping ([InAppThread], Bool, Error?) -> Void)

Parameters  

ParameterTypeDescription
beforeDateDateThe date indicating threads before which should be fetched.
limitIntThe maximum number of threads to fetch.
categoryStringThe category of threads to fetch.
threadTypeInAppThreadTypeThe type of threads to fetch.
completionHandler@escaping ([InAppThread], Bool, Error?)A closure to be executed when the operation completes.

Sample Code

let inApp = InAppMessagingProvider.instance
inApp.fetchThreads(beforeDate: Date(), limit: 10, category: nil, threadType: .conversation) {
  threads, hasMore, error in
  //Handle response
}
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
NSDate _*beforeDate = [NSDate date];    
[inApp fetchThreadsBeforeDate:beforeDate limit:10 category:nil threadType:InAppThreadTypeConversation completion:^(NSArray *threads, BOOL hasMore, NSError *error) {  
//Handle response   
  }]; 

fetchUnreadThreadCount(completionHandler: )

This method fetches the count of unread threads from the messaging service.

Syntax func fetchUnreadThreadCount(completionHandler: @escaping (Int, Error?) -> Void) 

Parameters  

ParameterTypeDescription
completionHandler@escaping ([InAppThread], Bool, Error?)A closure to be executed when the operation completes.

 Sample Code

let inApp = InAppMessagingProvider.instance
inApp.fetchUnreadThreadCount { count, error in
  //Handle response
}
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
[inApp fetchUnreadThreadCountWithCompletionHandler:^(NSInteger count, NSError _error) {    
//Handle response 
}]; 

publishMessage(_:  completionHandler:) 

This method publishes a message to the messaging service.

 Syntax:func publishMessage(_ message: InAppMessage, completionHandler: @escaping (Error?) -> Void) 

Parameters  

ParameterTypeDescription
messageInAppMessageThe message to be published.
completionHandler@escaping (Error?)- A closure to be executed when the operation completes.

 Sample Code

let inApp = InAppMessagingProvider.instance
let message = InAppMessage()
inApp.publishMessage(message) { error in
  //Handle error
}
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
InAppMessage *message = [[InAppMessage alloc] init];    
  [inApp publishMessage:message  completionHandler:^(NSError *error) {    
     if (error) {    
         // Handle error    
         NSLog(@"Error publishing message: %@", error.localizedDescription);    
    } else {    
         // Handle success    
         NSLog(@"Message published successfully");    
     }    
  }]; 

publishTypingIndicator(on: typing: ) 

This method publishes a typing indicator information on a thread.

 Syntax func publishTypingIndicator(on thread: InAppThread, typing: Bool) 

 Parameters 

ParameterTypeDescription
threadInAppThreadThe thread on which the information will be passed.
typingBoolInforms if the user has started typing or stopped typing.

 Sample Code

let inApp = InAppMessagingProvider.instance  
let thread = InAppThread()
inApp.publishTypingIndicator(on: thread, typing: true) 
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
InAppThread _*thread = [[InAppThread alloc] init]    
[inApp publishTypingIndicatorOn: thread typing: YES]; 

sendMessageStatus(for:  status: button: completionHandler:) 

This method sends message status updates for multiple messages to the messaging service. 

Syntax:func sendMessageStatus(for transactionId: String, status: InAppMessageStatus, button: InAppButton?, completionHandler: @escaping (Error?) -> Void) 

 Parameters 

ParameterTypeDescription
transactionIdStringThe transactionId of message to update the status for.
statusInAppMessageStatusThe new status of the messages.
buttonInAppButton?The button associated with the status update.
completionHandler@escaping (Error?) -> Void)A closure to be executed when the operation completes.

 Sample Code

let inApp = InAppMessagingProvider.instance  
let transactionId = "transId1"    
let inAppButton = InAppButton()    
inApp.sendMessageStatus(for: transactionId, status: .delivered, button: inAppButton) { error in
//Handle error 
} 
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
NSString *transactionId = @"transId1"; 
    InAppMessageStatus status = InAppMessageStatusDelivered; 
    [inApp sendMessageStatusFor:transactionId status:status button:nil completionHandler:^(NSError *error) { 
       if (error) { 
           NSLog(@"Error sending message status: %@", error.localizedDescription); 
       } else { 
           NSLog(@"Message status sent successfully"); 
       } 
    }]; 

sendMessageStatus(for:  status:  completionHandler: )

This methods sends message status updates for multiple messages to the messaging service.

Syntaxfunc sendMessageStatus(for transactionIds: [String], status: InAppMessageStatus, completionHandler: @escaping (Error?) -> Void) 

Parameters  

ParameterTypeDescription
transactionIds[String]The transactionIds of messages to update the status for.
statusInAppMessageStatusThe new status of the messages.
completionHandler@escaping (Error?) -> Void)A closure to be executed when the operation completes.

Sample Code

let inApp = InAppMessagingProvider.instance  
let transactionIds = ["transId1", "transId2"]    
inApp.sendMessageStatus(for: transactionIds, status: .delivered, button: nil) { error in  
//Handle error   
} 
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
NSArray *transactionIds = @[@"transId1", @"transId2"]; 
    InAppMessageStatus status = InAppMessageStatusDelivered; 
    [inApp sendMessageStatusFor:transactionIds status:status completionHandler:^(NSError *error) { 
       if (error) { 
           NSLog(@"Error sending message status: %@", error.localizedDescription); 
       } else { 
           NSLog(@"Message status sent successfully"); 
       } 
    }]; 

updateThread(_, completionHandler:) 

This method updates an existing thread on the messaging service. 

 Syntax func updateThread(_ thread: InAppThread, completionHandler: @escaping (InAppThread?, Error?) -> Void) 

 Parameter

ParameterTypeDescription
threadInAppThreadThe thread to be updated.
completionHandler@escaping (InAppThread?, Error?)A closure to be executed when the operation completes.

 Sample Code

let inApp = InAppMessagingProvider.instance  
inApp.updateThread(thread) { updatedThread, error in    
//Handle Error 
} 
id<InAppMessaging> inApp = [InAppMessagingProvider instance]; 
[inApp updateThread:[[InAppThread alloc] init] completionHandler:^(InAppThread *updatedThread, NSError *error) { 
    if (error) { 
       NSLog(@"Error updated thread: %@", error.localizedDescription); 
    } else { 
       NSLog(@"Successfully updated thread: %@", updatedThread); 
    } 
    }]; 

InAppMessagingDelegate

This protocol allows the interception of incoming messages and In-App Messaging connection status changes.

Methods

DidReceiveInAppMessage()

This method will be Invoked whenever a new InApp message is received and after processing the message internally.

Syntax: func didReceiveInAppMessage(_ message: InAppMessage)

Parameter:

ParameterTypeDescription
messageInAppMessageThe received message object.

Sample Code

func didReceiveInAppMessage(_ message: InAppMessage) {
  print("Received Message: \(message.description)")
}
- (void)didReceiveInAppMessage:(InAppMessage *)message {
  NSLog(@"Received Message:%@", [message description]);
}

didChangeConnectionStatus()

This method will be Invoked whenever there is a change to the In-App Messaging connection status.

Syntax: func didChangeConnectionStatus(_ connectionStatus: ConnectionStatus)

Parameter:

ParameterTypeDescription
connectionStatusConnectionStatusThe new current connection status.

Sample Code

func didChangeConnectionStatus(_ connectionStatus: ConnectionStatus) {
  let logMessage = "InApp didChangeConnectionStatus: \(connectionStatus.rawValue)"
  print(logMessage)
}
(void)didChangeConnectionStatus : (ConnectionStatus)connectionStatus {
  switch (connectionStatus) {
    case ConnectionStatusConnected:
      NSLog(@ "Connected");
      break;
    case ConnectionStatusConnecting:
      NSLog(@ "Connecting");
      break;
    case ConnectionStatusNone:
    case ConnectionStatusError:
    case ConnectionStatusClosed:
    case ConnectionStatusRefused:
    default:
      NSLog(@ "Not Connected");
      break;
  }
}

MediaFileManager

Methods:

upload(fileURL: , progressHandler: , completionHandler: )

Uploads a file from a URL.

Syntax:func upload(fileURL: URL, progressHandler: ((Double) -> Void)?, completionHandler: ((String?, Error?) -> Void)?)

Parameter:

ParameterTypeDescription
locationURLThe URL of the local file.
progressHandlerVoidA progressHandler that will be called with the upload progress as a Double, which indicates the percentage of the upload completed.
completionHandlerStringA completionHandler that will be called once the file is uploaded with the associated mediaId.

Sample Code

let mediaFileManager = InAppMessagingProvider.instance.mediaFileManager
mediaFileManager.upload(
  fileURL: localFileURL,
  progressHandler: { progress in
    print("Upload progress: \(progress)")
  },
  completionHandler: { mediaId, error in
    if let error = error {
      print("Upload failed: \(error)")
    } else if let mediaId = mediaId {
      print("File uploaded successfully. Media ID: \(mediaId)")
    }
  })
MediaFileManager *mediaFileManager =
    [InAppMessagingProvider instance].mediaFileManager;
[mediaFileManager uploadFileURL:localFileURL
    progressHandler:^(double progress) {
      NSLog(@"Upload progress: %f", progress);
    }
    completionHandler:^(NSString *mediaId, NSError *error) {
      if (error) {
        NSLog(@"Upload failed: %@", error);
      } else {
        NSLog(@"File uploaded successfully. Media ID: %@", mediaId);
      }
    }];

isFileUploading(from :)

Checks if the manager is currently uploading a file from a local URL.

Syntax: func isFileUploading(from location: URL) -> Bool

Returns: true if the file is currently being uploaded.

Parameter:

ParameterTypeDescription
locationBooleanThe local URL of the file.

Sample Code

let mediaFileManager = InAppMessagingProvider.instance.mediaFileManager
let localFileURL = // Provide ur local file url
let isUploading = mediaFileManager.isFileUploading(from: localFileURL)
MediaFileManager *mediaFileManager = [InAppMessagingProvider instance].mediaFileManager;
NSURL *localFileURL =  // Provide your local file url
BOOL isUploading = [mediaFileManager isFileUploadingFromLocation:localFileURL];

downloadFile(at : progressHandler: completionHandler:)

This method downloads a file from a URL.

Syntax: func downloadFile(at url: URL, progressHandler: ((Double) -> Void)?, completionHandler: @escaping ((URL?, Error?) -> Void))

Parameter:

ParameterTypeDescription
urlURLThe URL of the file.
progressHandler((Double) -> Void)?A progressHandler that will be called with the download progress as a Double, which indicates the percentage of the download completed.
completionHandler((URL?, Error?) -> Void))A completionHandler that will be called once the file is downloaded.

Sample Code

let mediaFileManager = InAppMessagingProvider.instance.mediaFileManager
let remoteFileURL =  // Provide ur remote file url
  mediaFileManager.downloadFile(
    at: remoteFileURL,
    progressHandler: { progress in
      print("Download progress: \(progress)")
    },
    completionHandler: { localFileURL, error in
      if let error = error {
        print("Download failed: \(error)")
      } else if let localFileURL = localFileURL {
        print("File downloaded to: \(localFileURL)")
      }
    })
MediaFileManager *mediaFileManager =
    [InAppMessagingProvider instance].mediaFileManager;
NSURL *remoteFileURL =  // Provide your remotefile url
    [mediaFileManager downloadFileAtURL:remoteFileURL
        progressHandler:^(double progress) {
          NSLog(@"Download progress: %f", progress);
        }
        completionHandler:^(NSURL *localFileURL, NSError *error) {
          if (error) {
            NSLog(@"Download failed: %@", error);
          } else {
            NSLog(@"File downloaded to: %@", localFileURL);
          }
        }];

isFileDownloading(from :)

Checks if the manager is currently downloading a file at a URL.

Syntax: func isFileDownloading(from location: URL) -> Bool

Returns: true if the file is currently being downloaded.

Parameter:

ParameterTypeDescription
locationURLThe URL of the file.

Sample Code

let mediaFileManager = InAppMessagingProvider.instance.mediaFileManager
let remoteFileURL = // Provide ur remote file url
let isDownloading = mediaFileManager.isFileDownloading(from: remoteFileURL)
MediaFileManager *mediaFileManager =
    [InAppMessagingProvider instance].mediaFileManager;
NSURL *remoteFileURL =  // Provide your local file url
    BOOL isDownloading =
        [mediaFileManager isFileDownloadingFromLocation:remoteFileURL];

getCachedFileUrl(for :)

Retrieves the filePath where the content of the file at the passed URL is stored.

Syntax: func getCachedFileUrl(for url: URL) -> URL?

Returns: The filePath where the content is locally located.

Parameter:

ParameterTypeDescription
urlURLThe URL where the content has been retrieved.

Sample Code

let mediaFileManager = InAppMessagingProvider.instance.mediaFileManager
let remoteFileURL = //Provide ur remote file url
let isDownloading = mediaFileManager.isFileDownloading(from: remoteFileURL)
MediaFileManager *mediaFileManager = [InAppMessagingProvider instance].mediaFileManager;
NSURL *remoteFileURL =  // Provide your local file url
BOOL isDownloading = [mediaFileManager isFileDownloadingFromLocation:remoteFileURL];

regenerateMediaURL(_ url: completionHandler:)

Regenerates new media URL for given URL upon checking expiry.

Syntax: func regenerateMediaURL(_ url: URL, completionHandler: @escaping (URL?, Error?) -> Void)

Parameter:

ParameterTypeDescription
urlURLThe URL to be regenerated.
completionHandler(URL?, Error?) -> Void)CompletionHandler is called with new mediaURL, If Request is success; nil otherwise.

Sample Code

let mediaFileManager = InAppMessagingProvider.instance.mediaFileManager
let remoteFileURL =  // Provide ur remote file url
  mediaFileManager.regenerateMediaURL(remoteFileURL) { newURL, error in
    if let error = error {
      print("Failed to regenerate media URL: \(error)")
    } else if let newURL = newURL {
      print("New media URL: \(newURL)")
    }
  }
MediaFileManager *mediaFileManager = [InAppMessagingProvider instance].mediaFileManager;
NSURL *remoteFileURL =  // Provide your local file url
    [mediaFileManager regenerateMediaURL:remoteFileURL
                       completionHandler:^(NSURL *newURL, NSError *error) {
                         if (error) {
                           NSLog(@"Failed to regenerate media URL: %@", error);
                         } else {
                           NSLog(@"New media URL: %@", newURL);
                         }
                       }];

Enumerations

ConnectionStatus

This enumeration describes different connection status between the SDK and the In-App Messaging server.

ValueDescription
noneNo connection attempt has been made.
connectingThe SDK is attempting to establish a connection with the In-App Messaging server.
connectedThe SDK is connected and allows you to publish and receive messages.
refusedThe connection is refused by the In-App Messaging server.
closedThe SDK is disconnected from the In-App Messaging server.
errorA connection error has occurred while connecting to the In-App Messaging server.

InAppFormFieldType

This enumeration describes the supported Form Fields.

ValueDescription
textIt denotes the Text type form field.
nameIt denotes the Name type form field.
emailIt denotes the Email type form field.
integerIt denotes the Integer type form field.
decimalIt denotes the Decimal type form field.
dateIt denotes the Date type form field.
dropdownIt denotes the Dropdown type form field.

InAppInteractiveDataType

This enumeration describes the Interactive data type for message.

ValueDescription
formResponseIt denotes the form response for message type “form”.
webURLIt denotes the response for “weburl” interactive data.
templatePostbackIt denotes the response for “postback” Template interactive data.
quickReplyPostbackIt denotes the response for “postback” quick reply interactive data.

InAppMessageStatus

This enumeration describes different status of a message.

ValueDescription
noneNone is the default message status.
notSentMessage failed to send.
sentMessage sent successfully to connect the platform.
deliveredMessage delivered to the user device.
readThe message read by the user device.
clickedMessage clicked.

InAppMessageType

This enumeration describes the InApp message types.

ValueDescription
messageThe message is a normal message.
messageDeletedThe message is deleted.
deliveryReceiptMessage is a DeliveryReceipt, TransactionId is available and can be used to match the receipt to the original message.
readReceiptMessage is a ReadReceipt, only TransactionId is available and can be used to match the receipt to the original message.
republishThe message is a republish of a MO, all data from the original message is available.
typingStartThe message is notifying that the recipient has started to type.
typingStopThe message is notifying that the recipient has stopped typing.
alertMessage is an alert from connect platform.
threadUpdateThe message is notifying that the thread has been updated.
clickedReceiptThe message is a clicked receipt.

InAppTemplateType

This enumeration describes the supported InApp Template Types.

ValueDescription
formIt denotes the Form template type.
genericIt denotes the Generic template type.

InAppThreadStatus

This enumeration describes the different status of a InApp thread.

ValueDescription
activeThe thread is active. The user can receive (and send if the thread type is a conversation) messages on this thread.
closedThe thread is closed. The user cannot receive (and send if the thread type is a conversation) any messages on this thread.

InAppThreadType

This enumeration describes the type of a thread.

ValueDescription
conversationThe thread is a conversation, the users can send messages on this thread.
announcementThe thread is an announcement thread, the users can only receive messages on this thread.

MessageSynchronizationMode

This enumeration describes the synchronization mode for messages.

ValueDescription
fullSynchronization should synchronize all available data.
limitedSynchronization should occur based on policy limits.
noneSynchronization should be disabled.