EMError error;
std::vector<std::string> mContacts;
mContacts = g_client->getContactManager().getContactsFromServer(error);
string ret;
if (error.mErrorCode == EMError::EM_NO_ERROR)
{
//通知界面刷新好友列表
}
else
{
//提示错误描述
cout << result->mDescription << endl;
}
chatClient->getContactManager().inviteContact("contact01", "hi, contact01");
添加好友需要等待对方的确认,也可以由程序设置成自动接受好友邀请。
chatClient->getContactManager().deleteContact("contact01", error);
//好友事件监听类(实现文件略):
class ContactListener : public EMContactListener {
public:
ContactListener() {
}
virtual void onContactAdded(const std::string &username);
virtual void onContactDeleted(const std::string &username);
virtual void onContactInvited(const std::string &username, std::string &reason);
virtual void onContactAgreed(const std::string &username);
virtual void onContactRefused(const std::string &username);
};
...
...
//注册好友事件监听类对象
ContactListener * mContactListener;
mContactListener = new ContactListener();
g_client->getContactManager().registerContactListener(mContactListener);
chatClient->getContactManager().acceptInvitation("contact01", error);