【问题标题】:iOS XMPP searching users by usernameiOS XMPP 按用户名搜索用户
【发布时间】:2013-09-23 10:13:58
【问题描述】:

我第一次在 iOS 中开发 XMPP 框架。任何人都可以帮助使用用户名搜索用户。

我已经尝试了以下链接中描述的方式。但没有运气。

iOS XMPP framework get all registered users

提前致谢。

【问题讨论】:

    标签: iphone ios objective-c ipad xmpp


    【解决方案1】:

    我终于明白了。我自己做的。

    NSString *userBare1  = [[[[self appDelegate] xmppStream] myJID] bare];    
    
    NSXMLElement *query = [NSXMLElement elementWithName:@"query"];
    [query addAttributeWithName:@"xmlns" stringValue:@"jabber:iq:search"];
    
    
    NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"jabber:x:data"];
    [x addAttributeWithName:@"type" stringValue:@"submit"];
    
    NSXMLElement *formType = [NSXMLElement elementWithName:@"field"];
    [formType addAttributeWithName:@"type" stringValue:@"hidden"];
    [formType addAttributeWithName:@"var" stringValue:@"FORM_TYPE"];
    [formType addChild:[NSXMLElement elementWithName:@"value" stringValue:@"jabber:iq:search" ]];
    
    NSXMLElement *userName = [NSXMLElement elementWithName:@"field"];
    [userName addAttributeWithName:@"var" stringValue:@"Username"];
    [userName addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1" ]];
    
    NSXMLElement *name = [NSXMLElement elementWithName:@"field"];
    [name addAttributeWithName:@"var" stringValue:@"Name"];
    [name addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
    
    NSXMLElement *email = [NSXMLElement elementWithName:@"field"];
    [email addAttributeWithName:@"var" stringValue:@"Email"];
    [email addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
    
    NSXMLElement *search = [NSXMLElement elementWithName:@"field"];
    [search addAttributeWithName:@"var" stringValue:@"search"];
    [search addChild:[NSXMLElement elementWithName:@"value" stringValue:searchField]];
    
    [x addChild:formType];
    [x addChild:userName];
    //[x addChild:name];
    //[x addChild:email];
    [x addChild:search];
    [query addChild:x];
    
    
    NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];
    [iq addAttributeWithName:@"type" stringValue:@"set"];
    [iq addAttributeWithName:@"id" stringValue:@"searchByUserName"];
    [iq addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"search.%@",[self appDelegate].hostName ]];
    [iq addAttributeWithName:@"from" stringValue:userBare1];
    [iq addChild:query];
    [[[self appDelegate] xmppStream] sendElement:iq];
    

    【讨论】:

    • 我在 iOS 中创建了一个应用程序并从 xmpp 连接和获取用户,并且也能够获取离线消息。现在我需要使用 XEP-0313 获取特定用户的对话,如何实现 XEP-第0313章
    【解决方案2】:

    正确答案。

    以下代码

    [iq addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"search.%@",[self appDelegate].hostName ]];
    

    表示

    XMPPJID *myJID = [[[self appdelegate] xmppStream] myJID];
    [iq addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"search.%@",myJID.domain]];
    

    【讨论】:

    • 哪个代表会处理这个?
    • 知道了,- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
    猜你喜欢
    • 2013-12-13
    • 2016-10-19
    • 2021-11-24
    • 1970-01-01
    • 2014-09-17
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    相关资源
    最近更新 更多