How to retrieve vCard in iOS from XMPP/OpenFire

丶灬走出姿态 提交于 2019-12-07 18:48:29

问题


As the name suggests I am trying to retrieve a vCard for a user using one of the next XMPPFrameworks methods:

- (XMPPvCardTemp *)fetchvCardTempForJID:(XMPPJID *)jid;
- (XMPPvCardTemp *)fetchvCardTempForJID:(XMPPJID *)jid useCache:(BOOL)useCache;

My current implementation is:

dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_PRIORITY_DEFAULT);
dispatch_async(queue, ^{

    XMPPvCardCoreDataStorage* xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
    XMPPvCardTempModule* m = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
    [m fetchvCardTempForJID:[sender myJID] ignoreStorage:YES];
    NSLog(@"%@",xmppvCardStorage.description);
                       });

The code above is not working and also I wanted to know how can I log the data, if the current approach is the right one.


回答1:


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);



回答2:


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.



来源:https://stackoverflow.com/questions/28897982/how-to-retrieve-vcard-in-ios-from-xmpp-openfire

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