XMPPFramework - How can I get a list of online and

2019-09-17 08:41发布

How can I get a list of online and offline friends using XMPPFramework in iOS?

I want to send buddy request to user. So how can I achieve this? Can somebody share some sample codes for me?

Thank you.

1条回答
We Are One
2楼-- · 2019-09-17 09:44

By using these methods you will get notified whole a user going to online/ offline, added, removed , updated etc.by using these methods you can update your contact list

- (void)xmppRoster:(XMPPRosterMemoryStorage *)sender didAddUser:(XMPPUserMemoryStorageObject *)user

- (void)xmppRoster:(XMPPRosterMemoryStorage *)sender didUpdateUser:(XMPPUserMemoryStorageObject *)user

- (void)xmppRoster:(XMPPRosterMemoryStorage *)sender didRemoveUser:(XMPPUserMemoryStorageObject *)user

- (void)xmppRoster:(XMPPRosterMemoryStorage *)sender
    didAddResource:(XMPPResourceMemoryStorageObject *)resource
          withUser:(XMPPUserMemoryStorageObject *)user

- (void)xmppRoster:(XMPPRosterMemoryStorage *)sender
 didUpdateResource:(XMPPResourceMemoryStorageObject *)resource
          withUser:(XMPPUserMemoryStorageObject *)user

- (void)xmppRoster:(XMPPRosterMemoryStorage *)sender
 didRemoveResource:(XMPPResourceMemoryStorageObject *)resource
          withUser:(XMPPUserMemoryStorageObject *)user

// To add buddy

- (void)addContactWithUserName:(NSString *)userName andNickName:(NSString *)nickName;
{
    if(userName)
    {
        XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",userName,self.hostName]];
        if(nickName)
        {
            [_xmppRoster addUser:jid withNickname:nickName];
        }
        else
        {
            [_xmppRoster addUser:jid withNickname:nil];
        }
    }
else
{
    NSLog(@"missing userName");
}
}
查看更多
登录 后发表回答