====== 好友管理 ======
----
==== 获取好友列表 ====
EMError error;
std::vector 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);
==== 拒绝加为好友 ====
chatClient->getContactManager().acceptInvitation("contact01", error);
----
上一页:[[im:windowssdk:chat|消息]]
下一页:[[im:windowssdk:group|群组管理]]