How to retrieve vCard in iOS from XMPP/OpenFire

六月ゝ 毕业季﹏ 提交于 2019-12-06 09:11:28

First create a instance of the appdelegate:

-(AppDelegate *) appDelegate{
return (AppDelegate *)[UIApplication sharedApplication].delegate;}

Then use below code to retrieve the vCard:

XMPPvCardTemp *vCard =[[self appDelegate].xmppvCardTempModule vCardTempForJID:[self appDelegate].xmppStream.myJID.bareJID shouldFetch:YES];

Here I have used the current user JID. You can used other users JID, but make sure that it should be a XMPPJID object.

Log it using the object of the XMPPvCardTemp

NSLog(@"%@", vCard.nickname);
NSLog(@"%@", vCard.name);
NSLog(@"%@", vCard.emailAddresses);
NSLog(@"%@", vCard.formattedName);
NSLog(@"%@", vCard.givenName);
NSLog(@"%@", vCard.middleName);

After requesting the vCard in the delegate method I have implemented:

- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule
        didReceivevCardTemp:(XMPPvCardTemp *)vCardTemp
                     forJID:(XMPPJID *)jid{

    XMPPvCardTemp *storedCard = [vCardTempModule vCardTempForJID:[XMPPJID jidWithString:@"newUser1@administrator"] shouldFetch:YES];
    NSLog(@"Stored card: %@",storedCard.prettyXMLString);

}

Witch prints out a nice string representation of the xml.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!