如何在iOs中获取用户的可用性通知?

时间:2016-03-24 09:48:11

标签: ios objective-c xmpp chat user-presence

我正在使用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

此致

1 个答案:

答案 0 :(得分:1)

我认为您需要使用以下代码发送在线状态:

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

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

所以在那之后我想以下方法叫做:

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