Chat / iOS
Chat iOS v4
Chat iOS
Chat
iOS
Home
/
Chat
/
iOS
/
Message
This is the new Docs for Chat SDK v4 for iOS. To see the previous Docs, click here.

Update a message

A user can update any of their own text and file messages sent using UserMessageUpdateParams and FileMessageUpdateParams. An error is returned if a user attempts to update another user's messages. In addition, channel operators can update any messages sent in the channel.

User message

var params = UserMessageUpdateParams(message: NEW_TEXT_MESSAGE)
params.customType = NEW_CUSTOM_TYPE
params.data = NEW_DATA

// The USER_MESSAGE_ID argument below indicates the unique message ID
// of a UserMessage object to update.
channel.updateUserMessage(messageId: USER_MESSAGE_ID, params: params) { (userMessage, error) in
    guard error == nil else {
        // Handle error.
        return
    }

    // The message is successfully updated.
    // Through the userMessage parameter of the callback method,
    // you could check if the update operation has been performed right.
}

File message

let params = FileMessageUpdateParams()
params.data = NEW_DATA
params.customType = NEW_CUSTOM_TYPE

// The FILE_MESSAGE_ID argument below indicates the unique message ID of a FileMessage object to update.
channel.updateFileMessage(messageId: FILE_MESSAGE_ID, params: params) { (fileMessage, error) in
    guard error == nil else {
        // Handle error.
        return
    }

    // The message is successfully updated.
    // Through the fileMessage parameter of the callback method,
    // you could check if the update operation has been performed right.
}

If a message is updated, the channel(_:didUpdate:) method in channel delegate will be invoked on all users' devices except the one that updated the message.

Open channel

class CustomViewController: UIViewController, OpenChannelDelegate {
    func initViewController() {
        SendbirdChat.add(self, identifier: self.delegateIdentifier)
    }

    func channel(_ channel: BaseChannel, didUpdate message: BaseMessage) {

    }
}

Group channel

class CustomViewController: UIViewController, GroupChannelDelegate {
    func initViewController() {
        SendbirdChat.add(self, identifier: self.delegateIdentifier)
    }

    func channel(_ channel: BaseChannel, didUpdate message: BaseMessage) {

    }
}