激活模块:
_vCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
_vCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:_vCardStorage];
_vCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:_vCardTempModule];
[_vCardTempModule addDelegate:self delegateQueue:dispatch_get_main_queue()];
[_vCardAvatarModule addDelegate:self delegateQueue:dispatch_get_main_queue()];
[_vCardTempModule activate:_xmppStream];
[_vCardAvatarModule activate:_xmppStream];
更新名片信息:
/// 更新名片信息
- (void)updateVCardMsg
{
XMPPvCardTemp *vcard = self.vCardTempModule.myvCardTemp;
/// 自定义xml扩展名片内容
DDXMLNode *node1 = [DDXMLNode elementWithName:@"key" stringValue:@"13877977999"];
DDXMLNode *node2 = [DDXMLNode elementWithName:@"key" stringValue:@"http://imgtu.4934501486627131.jpg"];
DDXMLNode *node3 = [DDXMLNode elementWithName:@"key" stringValue:@"美国"];
DDXMLNode *node4 = [DDXMLNode elementWithName:@"key" stringValue:@"广东"];
DDXMLNode *node5 = [DDXMLNode elementWithName:@"key" stringValue:@"广州"];
DDXMLNode *node6 = [DDXMLNode elementWithName:@"key" stringValue:@"男"];
DDXMLNode *node7 = [DDXMLNode elementWithName:@"key" stringValue:@"aaaa"];
vcard.nickname = @"nickname";
[vcard addChild:node1];
[vcard addChild:node2];
[vcard addChild:node3];
[vcard addChild:node4];
[vcard addChild:node5];
[vcard addChild:node6];
[vcard addChild:node7];
/// 向服务器更新名片
[_vCardTempModule updateMyvCardTemp:vcard];
}
vCard代理:XMPPvCardTempModuleDelegate
代理在登录成功后 和 调用 [_vCardTempModule updateMyvCardTemp:vcard]; 方法后都会有一次回调。
/// 获取到个人信息
- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule
didReceivevCardTemp:(XMPPvCardTemp *)vCardTemp forJID:(XMPPJID *)jid {}
发送IQ消息, 获取名片内容:
/// 发送IQ消息, 获取名片内容
- (void)getVCardMsgWithUserID:(NSString *)userID
{
XMPPIQ *iq = [XMPPIQ iqWithType:@"get"];
XMPPJID *JID = [XMPPJID jidWithUser:userID domain:@"domain" resource:@"resource"];
[iq addAttributeWithName:@"to" stringValue:JID.bare];
NSXMLElement *element = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"];
[iq addChild:element];
[_xmppStream sendElement:iq];
}
发送IQ消息后都会在 代理方法有回调
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
}