sy_im_sdk

Creator: coderz1093

Last updated:

0 purchases

sy_im_sdk Image
sy_im_sdk Images

Languages

Categories

Add to Cart

Description:

sy im sdk

sy_im_sdk #
依赖SDK #
下载依赖包 #
flutter pub get
copied to clipboard
iOS
在 iOS 项目的 podfile 头部中添加私有索引库
source 'http://code.bestsiyuhz.com/zgl/sypodspec.git'
source 'https://github.com/CocoaPods/Specs.git'

然后在 ios 工程根目录执行:
pod install --repo-update
copied to clipboard
初始化SDK #
构造SDK配置 #
SyOptions syOptions = SyOptions();
syOptions.appId = "您的AppID";
syOptions.secret = "您的secret";
//SDK运行环境
syOptions.environment=SyEnvironmentEnum.prod;
copied to clipboard
调用初始化方法: #
SyClient.getInstance().init(syOptions: syOptions);
copied to clipboard
用户登录 #
通过业务方UUID登录 #
SyClient.getInstance().loginByUUID(
uuid: "uuid", // 第三方 uuid, 测试使用, 正式请使用 token 方式登录
callback: SyCallBack(
onSuccess: (authInfo) {
//todo 处理登录成功逻辑
},
onFail: (code, msg) {
//todo 处理登录失败逻辑
})
);
copied to clipboard
通过token登录 #
SyClient.getInstance().loginByToken(
token: "token",
callback: SyCallBack(
onSuccess: (authInfo) {
//todo 处理登录成功逻辑
},
onFail: (code, msg) {
//todo 处理登录失败逻辑
})
);
copied to clipboard
会话管理 #
创建会话(无用户信息) #
SyClient.getInstance().conversationManager().createSignConversationByUid(userId: userId, callback: SyCallBack<SyConversation>(
onSuccess: (conversation) {
/*会回调会话的信息*/
/*sessionId 是会话id,发送消息需要*/
var sessionId = conversation.sessionId;
/*会话中对方存在sdk服务器的用户信息*/
var info = conversation.contact;
},
onFail: (code, msg) {
/*错误*/
})
);
copied to clipboard
创建会话(有用户信息) #
SyContact contact =SyContact();
//contact.userId 为必传字段,其他信息可以根据业务需要自行增加
contact.userId="";
contact.avatar="";
contact.nickName="";
SyClient.getInstance().conversationManager().createSignConversationByContact(contact: contact, callback: SyCallBack<SyConversation>(
onSuccess: (conversation) {
// conversation 回调会话的信息
// conversation.sessionId 是会话id,发送消息需要*/
},
onFail: (code, msg) {
//处理错误信息
})
);
copied to clipboard
获取会话列表 #
SyClient.getInstance().conversationManager().getConversationList(
callback: SyCallBack<List<SyConversation>>(onSuccess: (conversationList) {
/*会话列表*/
},
onFail: (code, msg) {
/*异常*/
})
);
copied to clipboard
初始化会话监听 #
ConversationListener listener = ConversationListener((conversationList) {

});
copied to clipboard
注册会话监听 #
SyClient.getInstance().conversationManager().addConversationListener(listener);
copied to clipboard
移除会话监听 #
SyClient.getInstance().conversationManager().removeConversationListener(listener);
copied to clipboard
会话开启聊天 #
SyClient.getInstance().conversationManager().addChatting(sessionId);
copied to clipboard
会话退出聊天 #
SyClient.getInstance().conversationManager().removeChatting(sessionId);
copied to clipboard
重置会话未读消息数量 #
SyClient.getInstance().conversationManager().restUnReadCount(sessionId);
copied to clipboard
获取单个会话未读消息数量 #
int num = await SyClient.getInstance().conversationManager().getUnReadNum(sessionId);
copied to clipboard
获取所有群聊会话未读消息数量 #
int num = await SyClient.getInstance().conversationManager().getAllUnReadNumBySessionType(sessionType: SessionType.GROUP);
copied to clipboard
获取所有单聊会话未读消息数量 #
int num = await SyClient.getInstance().conversationManager().getAllUnReadNumBySessionType(sessionType: SessionType.PRIVATE);
copied to clipboard
获取所有会话未读消息数量 #
int num = await SyClient.getInstance().conversationManager().getAllUnReadNum();
copied to clipboard
刷新所有会话未读消息数量 #
传入会话类型按照会话类型刷新:
SyClient.getInstance().conversationManager().restAllUnReadNum(sessionType: SessionTypeEnum.group);
copied to clipboard
不传入类型刷新所有会话
SyClient.getInstance().conversationManager().restAllUnReadNum();
copied to clipboard
聊天管理 #
获取聊天记录 #
SyMessage syMessage = SyMessage();
syMessage.msgTimeStamp = DateTime.timestamp().millisecond;
syMessage.sessionId = "会话ID";
int pageSize = 20;
SyClient.getInstance().chatManager().getMessageList(
starMessage: syMessage,
pageSize: pageSize,
callBack: SyCallBack(
onSuccess: (messageList) {
//todo 处理消息
},
onFail: (code, error) {
//todo 处理查询失败
})
);
copied to clipboard
发送消息 #
_getReceiveUserInfo() {
SyContact receiveUserInfo = SyContact();
receiveUserInfo.userId = "消息接收人用户ID";
receiveUserInfo.avatar = "接收人头像";
receiveUserInfo.nickName = "消息接收人用户昵称";
return receiveUserInfo;
}

//发送文本消息
_sendTxtMessage(String content) {
SyMessage syMessage = SyMessage.buildTxtMsg(_getReceiveUserInfo(), "会话ID");
syMessage.content=content;
SyClient.getInstance().chatManager().sendMessage(
syMessage: syMessage,
callBack: SyCallBack(onSuccess: (syMessage) {
//todo 发送成功回调
},
onFail: (code, error) {
//todo 发送失败回调
})
);
}

//发送图片消息(传入图片URI地址)
_sendImgMessage(Uri uri) {
SyMessage syMessage = SyMessage.buildImgMsg(_getReceiveUserInfo(), sessionId);
syMessage.uri=uri;
SyClient.getInstance().chatManager().sendMessage(
syMessage: syMessage,
callBack: SyCallBack(onSuccess: (syMessage) {
//todo 发送成功回调
},
onFail: (code, error) {
//todo 发送失败回调
})
);
}

//发送自定义消息
_sendCustomMessage(String content) {
SyMessage syMessage = SyMessage.buildCustomMsg(_getReceiveUserInfo(), sessionId);
syMessage.content=content;
SyClient.getInstance().chatManager().sendMessage(
syMessage: syMessage,
callBack: SyCallBack(onSuccess: (syMessage) {
//todo 发送成功回调
},
onFail: (code, error) {
//todo 发送失败回调
})
);
}
copied to clipboard
保存消息到本地 #
SyMessage syMessage = SyMessage.buildTxtMsg(_getReceiveUserInfo(), content);

SyClient.getInstance().chatManager().saveMessageToLocal(
syMessage: syMessage,
callBack: SyCallBack(
onSuccess: (syMessage) {
//todo 保存成功回调
},
onFail: (code, error) {
//todo 保存失败回调
},
),
);
copied to clipboard
删除消息 #
SyClient.getInstance().chatManager().deleteMessage(
msgId: "消息ID",
sessionId: '会话ID',
callBack: SyCallBack(
onSuccess: (bool status) {
//todo 处理删除成功逻辑
},
onFail: (String code, String error) {
//todo 处理删除失败逻辑
},
),
);
copied to clipboard
消息监听 #
1、初始化消息监听

OnMessageListener onMessageListener=OnMessageListener(
onMessage: (List<SyMessage> syMessage) {
//todo 处理新消息
},
onStatusChange: (List<SyMessage> syMessage) {
//todo 处理状态变更消息
},
)
2、注册消息监听

SyClient.getInstance().chatManager().addMessageListener(onMessageListener);

3、移除消息监听

SyClient.getInstance().chatManager().removeMessageListener(onMessageListener);
copied to clipboard
群组管理 #
获取群组详情 #
SyClient.getInstance().groupManager().getGroupDetail(
groupId: "groupId",
callBack: SyCallBack(
onSuccess: (groupData) {},
onFail: (code, err) {},
),
);
copied to clipboard
获取群组列表 #
SyClient.getInstance().groupManager().getGroupList(
callBack: SyCallBack(
onSuccess: (groupList) {},
onFail: (code, err) {},
),
);
copied to clipboard
从服务器获取群组列表 #
SyClient.getInstance().groupManager().getGroupListFromService(
callBack: SyCallBack(
onSuccess: (groupList) {},
onFail: (code, err) {},
),
);
copied to clipboard
退出群聊 #
SyClient.getInstance().groupManager().exitGroup(
groupId: "groupId",
callBack: SyCallBack(
onSuccess: (groupList) {},
onFail: (code, err) {},
),
);
copied to clipboard
添加群成员 #
SyClient.getInstance().groupManager().addGroupMember(
userId: "outUserId",
groupId: "groupId",
callBack: SyCallBack(
onSuccess: (groupList) {},
onFail: (code, err) {},
),
);
copied to clipboard
获取群成员 #
SyClient.getInstance().groupManager().getGroupMemberList(
groupId: "groupId",
callBack: SyCallBack(
onSuccess: (syContacts) {},
onFail: (code, err) {},
),
);
copied to clipboard
数据枚举 #
会话类型 #
package:sy_im_sdk/common/enum/session_type_enum.dart
copied to clipboard
消息状态 #
package:sy_im_sdk/common/enum/msg_status_enum.dart
copied to clipboard
消息类型 #
package:sy_im_sdk/common/enum/msg_type_enum.dart
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.