问题
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