Send image using xmpp infrastructure to iphone

I use the XMPP infrastructure on the iPhone for my chat application. I want to send an image from my application using the XMPP infrastructure. Can anyone suggest me how to do this?

Any help would be greatly appreciated.

+3
source share
3 answers

Add an additional tag, e.g.

<attachment>base64 of your image </attachment>

Thus, you sent your image to the sender side, converting it to a base64 string and converting the base64 string back to the image on the receiver side.

Uiimage base64, xmpp , . base64 base64encoded UIImage
:

http://iphonesdksnippets.com/post/2010/03/14/Convert-image-tofrom-text-%28Base64%29.aspx

... . - , , .

+6
    NSData *data = UIImageJPEGRepresentation(chosenImage, 1.0);

    Base64Transcoder *base64 = [[Base64Transcoder alloc] init];
    NSString *imgStr = [base64 base64EncodedStringfromData:data];


    NSXMLElement *ImgAttachement = [NSXMLElement elementWithName:@"attachment"];
    [ImgAttachement setStringValue:imgStr];
     NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
   [body setStringValue:@"image test"];


    NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:@"13iapp@jabbim.cz"];// [NSString stringWithFormat:@"%@@192.168.1.193",self.jabber_id]];

    [message addChild:message];
    [message addChild:ImgAttachement];

     [[[PDAppDelegate sharedDelegate] xmppStream]sendElement:message];
+1

Put the file on the WebDAV server and send the URL via XMPP, use XEP-0065 or XEP-0047 . Many who ask this question choose XEP-47, but it is almost always the wrong choice if the files are not very small, as many servers will punish your connection as a potential denial of service for sending large amounts of data.

0
source

Source: https://habr.com/ru/post/1781951/


All Articles