noob noob - 6 months ago 39
iOS Question

XMPPIQ doesn't set vCard tag in the vCard

I am trying to retrieve vCards for few JIDs, including the current user. I initialized and activated

XMPPvCardTempModule
using following code -

_xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
_xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:self.xmppvCardStorage];
_xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:self.xmppvCardTempModule];
[self.xmppvCardTempModule activate:self.xmppStream];
[self.xmppvCardAvatarModule activate:self.xmppStream];
[self.xmppvCardAvatarModule addDelegate:self delegateQueue:dispatch_get_main_queue()];
[self.xmppvCardTempModule addDelegate:self delegateQueue:dispatch_get_main_queue()];


And then I implemented the following delegate methods -

- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule
didReceivevCardTemp:(XMPPvCardTemp *)vCardTemp
forJID:(XMPPJID *)jid{
DDLogDebug(@"Received vCard for %@ \n vCard:%@",jid.full,vCardTemp.XMLString);
ContactCore* contact = [appDelegate.coreDataController findContact:jid.user];
contact.vCard = vCardTemp;
[appDelegate.dataController postContactUpdateNotification:contact];
}
- (void)xmppvCardTempModuleDidUpdateMyvCard:(XMPPvCardTempModule *)vCardTempModule{
[self.selfContact setVCard:vCardTempModule.myvCardTemp];
}
- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule failedToUpdateMyvCard:(DDXMLElement *)error{
DDLogDebug(@"failedToUpdateMyvCard Error: %@",error.XMLString);
}

-(void)xmppvCardAvatarModule:(XMPPvCardAvatarModule *)vCardTempModule didReceivePhoto:(UIImage *)photo forJID:(XMPPJID *)jid{
ContactCore* contact = [appDelegate.coreDataController findContact:jid.user];
}


The problem is that none of these delegate methods ever gets called. I can see the vCard output in the Log data which means that the vCards are getting fetched properly. So I implemented
didReceiveIQ
to get the vCards directly from the source, using the following code -

- (BOOL)xmppStream:(XMPPStream*)sender didReceiveIQ:(XMPPIQ *)iq{
XMPPvCardTemp *vCard = [XMPPvCardTemp vCardTempSubElementFromIQ:iq];
if(vCard){
ContactCore* contact = [appDelegate.coreDataController findContact:iq.from.user];
contact.vCard = vCard;
}
return NO;
}


But the
vCard
never gets initialized. I checked the IQs and I was receiving them properly. Then I checked the whole XML properly and found out that the
vCard
tag was absent and it was replaced with the actual name of the contact. For example this is what I was getting for one of the contact -

<iq
xmlns="jabber:client" from="xxx@xxx.com" to="xxx@xxx.com/xxx" id="12345" type="result">
<Abhi
xmlns="vcard-temp" prodid="-//HandGen//NONSGML vGen v1.0//EN" version="2.0">
<PHOTO>
<TYPE>image/jpeg</TYPE>
<BINVAL><!--A long Base64 code--></BINVAL>
</PHOTO>
</Abhi>
</iq>


The tag
<Abhi>
should be
<vCard>
for the
vCardTempSubElementFromIQ
method to identify it as a
vCard
. I want to know if it's a normal behavior or is there something I am doing wrong here? If it's something I am doing wrong, what should be the correct way to do it?

Answer

While saving a vCard I was using name property of the vCard to set name of the contact. This property actually changes the tag name, not the contact name. I started using nickname property after realizing my mistake.