I am using XMPPFramework for creating my chat app. I want to update the Avatar of the current user. I have used ImagePicker for this. Here's how my updateAvatar method looks like -
- (void)updateAvatar:(UIImage *)avatar
{
NSData *imageData = UIImageJPEGRepresentation(avatar, 0.5f);
imageData = [imageData base64EncodedDataWithOptions:NSDataBase64Encoding64CharacterLineLength];
dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_PRIORITY_DEFAULT);
dispatch_async(queue, ^{
XMPPvCardTempModule *vCardTempModule = self.xmppvCardTempModule;
XMPPvCardTemp *myVcardTemp = [vCardTempModule myvCardTemp];
if (!myVcardTemp)
{
NSXMLElement *vCardXML = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"];
myVcardTemp = [XMPPvCardTemp vCardTempFromElement:vCardXML];
}
//[myVcardTemp setName:[NSString stringWithFormat:@"%@",name.text]];
[myVcardTemp setPhoto:imageData];
[vCardTempModule updateMyvCardTemp:myVcardTemp];
});
}
But when I get the vCard back, the image turns out to be an invalid image. I have checked this question already. It's creating vCard element manually while I used setPhoto method on vCard. I tried with UIImagePNGRepresentation too, but it doesn't work either.
Any idea what could be wrong here?
Looks like I just needed to do this -
NSData *imageData1 = UIImageJPEGRepresentation(avatar,0.0);
XMPPvCardTemp *myvCardTemp = [self.xmppvCardTempModule myvCardTemp];
if (myvCardTemp) {
[myvCardTemp setPhoto:imageData1];
[self.xmppvCardTempModule updateMyvCardTemp:myvCardTemp];
}
Converting to Base64 was not required at all.