Send and retrieve images and video using swift + xmppframework

90 views
Skip to first unread message

Hind Amer

unread,
Oct 7, 2018, 7:15:40 AM10/7/18
to XMPPFramework
Hi everybody, 
I am building real chat app and I am struggling with sending and retrieving images and videos. can some body send me code .... I am not sure how to convert the image to string and upload it then download it as an image. 

this is in the viewController

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String:Any]){

        

       

        let imgTemp = info[UIImagePickerControllerOriginalImage] as? UIImage// get image from imagePickerViewController

        print("This is the Pic Info *** \(String(describing: imgTemp))")

        XmppManager.sharedInstance.sendImageMessage(toUser: (currentChats?.nameUser!)!, imageToUser: imgTemp?.images)

        if imgTemp != nil {

        let message = MessageShared()

        message.isOwnnertrue

        message.messages = ""

        message.userImageUrl = imgTemp as? UIImage

        currentChats?.message.append(message)

        textMessageView.text = ""

        }

        

        tableView.reloadData()


        imagePicker.dismiss(animated: true, completion: nil)


        

        

    }






the send function 



 func sendImageMessage(toUser jid:String, imageToUser Image:UIImage) -> () {

        let dataFile = UIImagePNGRepresentation(Image)

        let imgStr = dataFile?.base64EncodedString()

        

        let body = DDXMLElement.element(withName: "body") as! DDXMLElement

         let imageAttachement = DDXMLElement.element(withName: "attachment", stringValue: imgStr!) as! DDXMLElement

        let messageID = self.xmppStream?.generateUUID

        

        body.stringValue = "Upload Image"

        let completeMessage = DDXMLElement.element(withName: "message") as! DDXMLElement

        

        completeMessage.addAttribute(withName: "id", stringValue: messageID!)

        completeMessage.addAttribute(withName: "type", stringValue: "chat")

        completeMessage.addAttribute(withName: "to", stringValue: jid)

        completeMessage.addChild(body)

        completeMessage.addChild(imageAttachement)

        

        let active = DDXMLElement.element(withName: "active", stringValue:

            "http://jabber.org/protocol/disco#items") as! DDXMLElement

        completeMessage.addChild(active)

        

        self.xmppStream?.send(completeMessage)

    }



thanks...

Bilal Tahir

unread,
Oct 7, 2018, 10:00:49 AM10/7/18
to XMPPFramework
hi,

You can use XEP-0066 extension  XMPPOutOfBandMessaging class for send media messgage. it can be image, audio or video. 

self.xmppOutOfBandMessaging.submitOutgoingMessage(msg, withOutOfBandData: data, mimeType: messageModel.mimeType)


You can get acknowledgment of media message by its delegate methods of XMPPOutOfBandMessaging class.



Hind Amer

unread,
Oct 8, 2018, 2:46:14 PM10/8/18
to XMPPFramework


On Sunday, October 7, 2018 at 5:00:49 PM UTC+3, Bilal Tahir wrote:
hi,

You can use XEP-0066 extension  XMPPOutOfBandMessaging class for send media messgage. it can be image, audio or video. 

self.xmppOutOfBandMessaging.submitOutgoingMessage(msg, withOutOfBandData: data, mimeType: messageModel.mimeType)


You can get acknowledgment of media message by its delegate methods of XMPPOutOfBandMessaging class.


Hi,

 first I want to thank you for your reply. second , I tried to implemented but I am not sure I have add the delegate 

 func xmppOutOfBandResourceMessaging(_ xmppOutOfBandResourceMessaging: XMPPOutOfBandResourceMessaging, didReceiveOutOfBandResourceMessage message: XMPPMessage) {

        print("we recieved something from XMPPOUTOFBAnd")

    }

but when it coms to the send I could not found this ?

self.xmppOutOfBandMessaging.submitOutgoingMessage(msg, withOutOfBandData: data, mimeType: messageModel.mimeType)


really I need help I could not find somebody that implemented using this class so I need to see some thing if you do not mind in swift.

I tried to add it in the  imagePickerController but it was not predefined.

Thanks in advance 


 

Hind Amer

unread,
Oct 9, 2018, 4:19:09 AM10/9/18
to XMPPFramework
Hi again, 
I also tried to add these 

 var xmppOutOfBandMessaging: XMPPOutOfBandMessaging

 var xmppOutOfBandMessagingStorage: XMPPOutOfBandMessagingFilesystemStorage


but I get an error (Use of undeclared type 'XMPPOutOfBandMessaging')


I just can add  ->   var xmppOutofBandData = XMPPOutOfBandResourceMessaging()



Reply all
Reply to author
Forward
0 new messages