Kommunicate-io/Kommunicate-iOS-SDK

Issue with metaData in iOS

dubey07neha opened this issue · 2 comments

Hi,
How to send metadata with kmConversationBuilder in iOS? I can't see any function in documentation where we can send the meta data with kmConversationBuilder. Although I can see this in android documentation. Any help would be appreciated.

Thanks!

Hi, you can pass the metadata like this:

var conversationMetadata: [String: Any] = [:]
do {
    let conversationInfo = ["custom-key": "value"]
    let conversationInfoData = try JSONSerialization.data(withJSONObject: conversationInfo, options: .prettyPrinted)
    let conversationInfoString = String(data: conversationInfoData, encoding: .utf8) ?? ""

    conversationMetadata = ["info": conversationInfoString]
} catch {
    print(error)
}
let kmConversation = KMConversationBuilder()
    .useLastConversation(false)
    .withMetaData(conversationMetadata)
    .build()

Kommunicate.createConversation(conversation: kmConversation) { result in
    switch result {
    case .success(let conversationId):
        print("Conversation id: ",conversationId)
    // Launch conversation
    case .failure(let kmConversationError):
        print("Failed to create a conversation: ", kmConversationError)
    }
}

A friendly reminder that this issue had no activity for 30 days.