Contact List

Learn how to create, update, manage, and add users to your contact list.

The Contact List API is rather straightforward. A user A sends a request to become "friends" with a user B. The user B accepts the friend request. And now the user A and B appear in each other roster.

Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.

Before you begin

  1. Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
  2. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  3. Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.
  4. Connect to the Chat server. See our Connection page to learn how to do it.

Access contact list

The following function gives you access to all contact list items.

// array of accepted contacts
let contacts = QBChat.instance.contactList?.contacts

// array of pending requests
let pendingRequests = QBChat.instance.contactList?.pendingApproval
// array of accepted contacts
NSArray *contacts = QBChat.instance.contactList.contacts;

// array of pending requests
NSArray *pendingApproval = QBChat.instance.contactList.pendingApproval;

Add user to your contact list

To add a user to the contact list, use the following snippet.

let userID: UInt = 34
QBChat.instance.addUser(toContactListRequest: userID) { (error) in
    
}
NSUInteger userID = 34;
[QBChat.instance addUserToContactListRequest:userID completion:^(NSError * _Nullable error) {
    
}];

📘

Maximum number of contacts is 300.

The QBChat instance will call its delegate’s chatDidReceiveContactAddRequest(fromUser:) method and the user will receive the request to be added to the contact list.

//MARK: QBChatDelegate
func chatDidReceiveContactAddRequest(fromUser userID: UInt) {
    
}
//MARK: QBChatDelegate
- (void)chatDidReceiveContactAddRequestFromUser:(NSUInteger)userID {
    
}

Confirm the contact request

To confirm the request, use confirmAddContactRequest() method.

QBChat.instance.confirmAddContactRequest(userID) { (error) in
    
}
[QBChat.instance confirmAddContactRequest:userID completion:^(NSError * _Nullable error) {
    
}];

The QBChat instance will call chatDidReceiveAcceptContactRequest(fromUser:) delegate method and this user will be informed that you have accepted the contact request.

//MARK: QBChatDelegate
func chatDidReceiveAcceptContactRequest(fromUser userID: UInt) {
    
}
//MARK: QBChatDelegate
- (void)chatDidReceiveAcceptContactRequestFromUser:(NSUInteger)userID {
    
}

Reject the contact request

To reject the request, use the rejectAddContactRequest() method.

QBChat.instance.rejectAddContactRequest(userID) { (error) in
    
}
[QBChat.instance rejectAddContactRequest:userID completion:^(NSError * _Nullable error) {
    
}];

The QBChat instance will call its chatDidReceiveRejectContactRequest(fromUser:) delegate method and this user will be informed that you have declined the contact request.

//MARK: QBChatDelegate
func chatDidReceiveRejectContactRequest(fromUser userID: UInt) {
    
}
//MARK: QBChatDelegate
- (void)chatDidReceiveRejectContactRequestFromUser:(NSUInteger)userID {
    
}

Remove user from the contact list

To remove a previously added user from the contact list, use the following method.

QBChat.instance.removeUser(fromContactList: 34) { (error) in
    
}
[QBChat.instance removeUserFromContactList:34 completion:^(NSError * _Nullable error) {
    
}];

Contact list updates

You can also track contact list updates in a real time by using delegates.

//MARK: QBChatDelegate
func chatContactListDidChange(_ contactList: ContactList) {
    
}
//MARK: QBChatDelegate
- (void)chatContactListDidChange:(QBContactList *)contactList {
    
}

What’s Next