XMPPFramework - 如何更改我的个人资料状态?

时间:2012-12-29 07:03:41

标签: ios xmpp xmppframework user-presence

为了更改我的记录状态,我使用了以下代码:

    XMPPPresence *presence = [XMPPPresence presenceWithType:@"away"];
    [[self xmppStream] sendElement:presence];

但我没有得到[self xmppStream]的参考资料。所以我改为以下代码:

    XMPPPresence *presence = [XMPPPresence presence];
    NSXMLElement *status = [NSXMLElement elementWithName:@"status"];
    [status setStringValue:@"away"];
    [presence addChild:status];
    NSError *error = nil;

    xmppStream = [[XMPPStream alloc] init];
    [xmppStream disconnect];
    NSString *myJID = [NSString stringWithFormat:@"%@", appDelegate.jid];
    XMPPJID *JID;        
    JID = [XMPPJID jidWithString:myJID];
    NSLog(@"%@",JID);
    [xmppStream setMyJID:JID];
    xmppStream.hostName=@"talk.google.com";

    [xmppStream connect:&error];        
    [xmppStream sendElement:presence];

仍未获得更改状态。请分享您的想法。提前谢谢。

2 个答案:

答案 0 :(得分:1)

您必须等到连接后才能发送节,方法是听代表上的xmppStreamDidAuthenticate

另外,在广播你的存在时,不要费心去设置或来自JID。

答案 1 :(得分:1)

您可以在goOnline之后通过xmppStreamDidAuthenticate方法登录后立即更改您的状态。

- (void)goOnline
{
    // Initialize XMPPPresence variable
    XMPPPresence *presence = [XMPPPresence presence];

    // Initialize XML element <show/> for specifying your status
    NSXMLElement *show = [NSXMLElement elementWithName:@"show"];

    // Initialize XML element <status/> for describing your status
    NSXMLElement *status = [NSXMLElement elementWithName:@"status"];

    // If you want your user status to be shown as "Available"
    [show setStringValue:@"chat"];
    [status setStringValue:@"Available"];

    // If you want your user status to be shown as "Busy"
    [show setStringValue:@"dnd"];
    [status setStringValue:@"Busy"];

    // If you want your user status to be shown as "Away"
    [show setStringValue:@"away"];
    [status setStringValue:@"Away"];

    // If you want your user status to be shown as "Off-day"
    [show setStringValue:@"xa"];
    [status setStringValue:@"Off-day"];

    // Add the XML elements to XMPPPresence
    [presence addChild:show];
    [presence addChild:status];

    // Update new presence to server
    [xmppStream sendElement:presence];
}

有关上述代码的详细信息和说明,请访问Change XMPPPresence to Away/Busy/Invisible