0

我正在使用 XMPP 开发基于聊天的应用程序。我被困在获取用户上线或下线的通知。

当任何名册好友上线或下线时,不会调用以下方法。

- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{

    NSString *presenceType = [presence type]; // online/offline
    NSString *myUsername = [[sender myJID] user];
    NSString *presenceFromUser = [[presence from] user];
    if (![presenceFromUser isEqualToString:myUsername])
    {
        if ([presenceType isEqualToString:@"available"]) {
            // [_chatDelegate newBuddyOnline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, @"chat.denederlandsewateren.nl"]];
        } else if ([presenceType isEqualToString:@"unavailable"]) {
            // [_chatDelegate buddyWentOffline:[NSString stringWithFormat:@"%@@%@", presenceFromUser, @"chat.denederlandsewateren.nl"]];
        }
    }
}

请建议我或指导我如何处理- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence

问候,

4

1 回答 1

1

我认为您需要使用以下代码发送出席信息:

NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"];
[xmppStream sendElement:presence];

或者

XMPPPresence *presence = [XMPPPresence presence];
    [[self xmppStream] sendElement:presence]; 

所以在那之后我猜下面的方法叫做:

 -(void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
于 2016-03-25T06:10:18.910 回答