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.

Delete a message

Users can delete any message they themselves have sent. An error is returned if a user attempts to delete messages sent by other users. Also channel operators can delete any messages in a channel. This works the same way for both open channels and group channels.

channel.deleteMessage(messageId: MESSAGE_ID) { error inin
    guard error == nil else {
        // Handle error.
        return
    }

    // The message is successfully deleted from the channel.
}

After a message has been deleted, the channel(_:messageWasDeleted:) method in channel delegate is invoked on all users' devices including the device where the message was deleted.

Open channel

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

    func channel(_ channel: BaseChannel, messageWasDeleted messageId: Int64) {

    }
}

Group channel

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

    func channel(_ channel: BaseChannel, messageWasDeleted messageId: Int64) {

    }
}