1

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

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

仍然没有得到改变的状态。请分享你的想法。提前致谢。

4

2 回答 2

1

您必须等到连接后才能发送节,方法是监听xmppStreamDidAuthenticate委托。

此外,在广播您的存在时,不要费心设置 to 或 from JID。

于 2012-12-29T07:45:15.143 回答
1

您可以在登录后立即通过goOnline调用 after 的方法更改您的状态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];
}

有关我上面代码的更多信息和解释,请访问将 XMPPPresence 更改为 Away/Busy/Invisible

于 2014-07-16T13:12:58.077 回答