XMPPFramework - How can I get a list of online and offline friends?

我的未来我决定 提交于 2019-12-25 03:24:19

问题


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:


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");
}
}


来源:https://stackoverflow.com/questions/24522526/xmppframework-how-can-i-get-a-list-of-online-and-offline-friends

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!