SBDFileMessage's type property

The docs only say that the type property is a string. Could I please get some guidance on how to interpret that property. My assumption would be that these are Mime types. Is this correct?

@tvon,

This is a classification that we use to determine a message type. For example, you can see how this may be used when you receive messages through a channel delegate:

class GroupChannelChattingViewController: UIViewController, SBDChannelDelegate {
    SBDMain.add(self, identifier: self.delegateIdentifier)

    func channel(_ sender: SBDBaseChannel, didReceive message: SBDBaseMessage) {
        // You can customize how to display the different types of messages with the result object in the "message" parameter.
        if message is SBDUserMessage {
            ...
        }
        else if message is SBDFileMessage {
            ...
        }
        else if message is SBDAdminMessage {
            ...
        }
    }
}
1 Like

Thanks for the response. That makes sense. I’m actually curious about the type property specifically on the SBDFileMessage. In order to distinguish between different file types such as video, images, etc.

You are right! The mime type is preferred. Here is the example.

3 Likes

To follow up on Miyoung’s response, you can see an example of how we utilize this in our sample app:

        else if message is SBDFileMessage {
            let fileMessage = message as! SBDFileMessage
            let sender = fileMessage.sender
            
            if fileMessage.type.hasPrefix("image") {
                body = String(format: "%@: (Image)", (sender?.nickname)!)
            }
            else if fileMessage.type.hasPrefix("video") {
                body = String(format: "%@: (Video)", (sender?.nickname)!)
            }
            else if fileMessage.type.hasPrefix("audio") {
                body = String(format: "%@: (Audio)", (sender?.nickname)!)
            }
            else {
                body = String(format: "%@: (File)", sender!.nickname!)
            }
        }
2 Likes

Awesome. Appreciate your help @Tyler and @Miyoung_Han

1 Like