XMPPFramework - How can I update my own avatar image?

I am developing an application in which I want to update an avatar image. I follow the XEP-0153 recommendations for updating the avatar image, and I built an NSXMLElement corresponding to the following code in XEP-0153 , and sent this element through XMPPStream .

 <iq from=' juliet@capulet.com ' type='set' id='vc1'> <vCard xmlns='vcard-temp'> <PHOTO> <TYPE>image/jpeg</TYPE> <BINVAL> Base64-encoded-avatar-file-here! </BINVAL> </PHOTO> </vCard> </iq> 

The server responds to the following error:

 <iq xmlns="jabber:client" type="error" id="vc1" to=" vvreddy50@gmail.com /83557F96"> <vCard xmlns="vcard-temp"> <photo> <type>image/jpeg</type> <binval>Base64-encoded-avatar-file-here</binval> </photo> </vCard> <error code="500" type="wait"> <internal-server-error xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"> </internal-server-error> </error> </iq> 

Instead of <iq to=' juliet@capulet.com ' type='result' id='vc1'/>

Please, can you post a code or link related to updating the avatar image? Thanks in advance.

+4
source share
3 answers
 - (void)updateAvatar:(UIImage *)avatar { NSData *imageData = UIImagePNGRepresentation(avatar); dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_PRIORITY_DEFAULT); dispatch_async(queue, ^{ XMPPvCardTempModule *vCardTempModule = [[XMPPHandler sharedInstance] xmppvCardTempModule]; XMPPvCardTemp *myVcardTemp = [vCardTempModule myvCardTemp]; [myVcardTemp setName:[NSString stringWithFormat:@"%@",name.text]]; [myVcardTemp setPhoto:imageData]; [vCardTempModule updateMyvCardTemp:myVcardTemp]; }); } 
+10
source

#import "XMPPvCardTemp.h"

  - (void)updateAvatar:(UIImage *)avatar{ NSData *imageData1 = UIImageJPEGRepresentation(avatar,0.5); NSXMLElement *vCardXML = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"]; NSXMLElement *photoXML = [NSXMLElement elementWithName:@"PHOTO"]; NSXMLElement *typeXML = [NSXMLElement elementWithName:@"TYPE"stringValue:@"image/jpeg"]; NSXMLElement *binvalXML = [NSXMLElement elementWithName:@"BINVAL" stringValue:[imageData1 base64Encoding]]; [photoXML addChild:typeXML]; [photoXML addChild:binvalXML]; [vCardXML addChild:photoXML]; XMPPvCardTemp *myvCardTemp = [[[self appDelegate] xmppvCardTempModule]myvCardTemp]; if (myvCardTemp) { [myvCardTemp setPhoto:imageData1]; [[[self appDelegate] xmppvCardTempModule] updateMyvCardTemp :myvCardTemp]; } else{ XMPPvCardTemp *newvCardTemp = [XMPPvCardTemp vCardTempFromElement:vCardXML]; [[[self appDelegate] xmppvCardTempModule] updateMyvCardTemp:newvCardTemp]; } } 
+3
source

From the XMPP Core RFC , <error type='wait'> means:

try again after waiting (error is temporary)

therefore, your code should wait a while and resubmit the request.

(It is assumed that you are actually sending a base64 encoded JPEG image as the BINVAL your business card. The response from the server does not match the request that you said you sent, so I assume that you have edited both options. It would be better to enable exact request and answer to your question, but crop base64 encoded image with multiple characters to get brackets.)

+1
source

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


All Articles