Skip to content

MQTT Subscriber Setup with Channelize API SDK

rohitphogat19 edited this page Mar 12, 2019 · 3 revisions

In IOS SDKs, we have implemented MQTT as the pub sub protocol that is user for delivering data.

Add or Remove Conversation Data Delegate

To receive certain events happening in the conversations from Channelize server you need to register CHConversationDataDelegate with it's unique ID. You need to implement the following functions/events to keep getting the information related to the conversations.

// ViewController.swift
class ViewController: UIViewController, CHConversationDataDelegate {
    override func viewdidLoad() {
        
        // ...
        Channelize.addConversationDelegate(self, identifier: UNIQUE_DELEGATE_ID)
        
        // ...
    }

    // If any change in conversation Object like admin changed,member added, title change etc.
    func didGetChatInfo(conversation: CHConversation?) {
    }

    // Any new message is Recieved
    func didReceiveNewMessage(message: CHMessage?){
    }

    // If any conversation is Deleted
    func didDeleteChat(conversation: CHConversation?){
    }

    // If any Conversation is Cleared
    func didClearChat(conversation: CHConversation?){
    }

    // If any message is deleted
    func didDeleteMessage(conversation: CHConversation?){
    }

    // If any member is added in Group
    func didMemberAdded(conversation: CHConversation?){
    }

    // If any member is removed from Group
    func didMemberRemoved(conversation: CHConversation?){
    }

    // If admin is added in group
    func didAdminAdded(conversationId:String?, isAdmin:Bool, userId:String?){
    }

    // If any message is mark as read
    func didMarkAsRead(messageId:String?,conversationId:String?,userId:String?,status:Int?,isMe:Bool){
    }

    // if Typing status is changed
    func didChangeTypingStatus(conversationId:String?,userId:String?,isTyping:Bool){
    }

    // If messages are deleted
    func didMessagesDeleted(messageIds:[String],topic:String){
    }
}

The following code shows how to remove the event data delegate.

Channelize.removeDelegate(forDelegateId: UNIQUE_DELEGATE_ID)

Add or Remove User Event Delegate

To receive certain events happening related to the users from Channelize server you need to register CHUserEventDelegate with it's unique ID. You need to implement the following functions/events to keep getting the information related to the users.

// ViewController.swift
class ViewController: UIViewController, CHUserEventDelegate {
    override func viewdidLoad() {
        
        // ...
        Channelize.addUserDelegate(self, identifier: UNIQUE_DELEGATE_ID)
        
        // ...
    }
    // Any new contact is added
    func didUserAdded(user: CHUser?) {
    }
    
    // Any contact removed from your contact list
    func didUserRemoved(user: CHUser?) {
    }
    
    // If Contact online offline status changed
    func didChangeUserStatus(user: CHUser?){
    }
    
    // If any contact blocked me
    func didUserBlocked(isMe:Bool,userId:String?){
    }
    
    // if ant Contact unblocked me
    func didUserUnblocked(isMe:Bool,user: CHUser?){
    }
}

Add or Remove Connection Delegate

To receive certain events related to the server connection you need to register CHConnectionDelegate with it's unique ID. You need to implement the following functions/events to keep getting the information related to the users.

// ViewController.swift
class ViewController: UIViewController, CHConnectionDelegate {
    override func viewdidLoad() {
        
        // ...
        Channelize.addConnectionDelegate(self, identifier: UNIQUE_DELEGATE_ID)
        
        // ...
    }
     
    func didStartReconnection(){
    }
    
    func didServerConnected(){
    }
    
    func didServerDisconnected(){
    }
    
    func didConnectionFailed(){
    }
}