Search code examples
swiftmapboxjsqmessagesviewcontroller

How can I use mapbox in JSQMessagesViewController swift


How can i display a Mapbox map in a JSQMessagesViewController bubble in swift? Any help would be appreciated.


Solution

  • You have to create a class which conforms JSQMessageMediaData protocol to create your media data

    Code:

    import JSQMessagesViewController
    
    class ProductChatMsg: NSObject, JSQMessageMediaData {
    func mediaView() -> UIView! {
        let view = Bundle.main.loadNibNamed("XXView", owner: self, options: nil)?[0] as! UIView
    
        return view
    }
    
    func mediaViewDisplaySize() -> CGSize {
        return CGSize(width: 228, height: 156)
    }
    
    func mediaPlaceholderView() -> UIView! {
        return UIView()
    }
    
    func mediaHash() -> UInt {
        return UInt(self.hash)
    }
    }