1
我正在嘗試爲少數JID(包括當前用戶)檢索vCards。我初始化,並使用下面的代碼激活XMPPvCardTempModule
-XMPPIQ未在vCard中設置vCard標記
_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()];
然後我採取了以下委託方法 -
- (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];
}
的問題是,沒有這些委託方法不斷被調用。我可以在日誌數據中看到vCard輸出,這意味着vCard正在被正確讀取。所以,我實現直接從源獲得電子名片,使用下面的代碼 -
- (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;
}
但vCard
永遠不會被初始化。我檢查了智商,我正確地收到了他們。然後,我正確地檢查了整個XML,發現vCard
標記不存在,它被替換爲聯繫人的實際名稱。例如,這就是我正在爲一個接觸 -
<iq
xmlns="jabber:client" from="[email protected]" to="[email protected]/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>
標籤<Abhi>
應<vCard>
爲vCardTempSubElementFromIQ
方法來識別它作爲一個vCard
。我想知道這是否是一種正常行爲,或者我在這裏做錯了什麼?如果這是我做錯的事情,應該怎麼做纔是正確的做法呢?