Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
22b0f661
Commit
22b0f661
authored
Nov 25, 2024
by
David黄金龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调通 相关IM接口
parent
51648b74
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
170 additions
and
25 deletions
+170
-25
YHIMTestViewController.swift
...vestreamSales(直播销售)/IM(环信)/C/YHIMTestViewController.swift
+170
-25
No files found.
galaxy/galaxy/Classes/Modules/LivestreamSales(直播销售)/IM(环信)/C/YHIMTestViewController.swift
View file @
22b0f661
...
@@ -10,6 +10,8 @@ import UIKit
...
@@ -10,6 +10,8 @@ import UIKit
import
HyphenateChat
import
HyphenateChat
class
YHIMTestViewController
:
YHBaseViewController
{
class
YHIMTestViewController
:
YHBaseViewController
{
private
let
roomID
:
String
=
"265249570750475"
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
...
@@ -17,6 +19,17 @@ class YHIMTestViewController: YHBaseViewController {
...
@@ -17,6 +19,17 @@ class YHIMTestViewController: YHBaseViewController {
//1.
//1.
gk_navTitle
=
"IM 测试"
gk_navTitle
=
"IM 测试"
let
addBtn
=
UIButton
()
addBtn
.
setTitle
(
"发送"
,
for
:
.
normal
)
view
.
addSubview
(
addBtn
)
addBtn
.
snp
.
makeConstraints
{
make
in
make
.
centerX
.
centerY
.
equalToSuperview
()
make
.
height
.
width
.
equalTo
(
200
)
}
addBtn
.
backgroundColor
=
UIColor
.
red
//for test hjl
addBtn
.
addTarget
(
self
,
action
:
#selector(
sendMessage
)
,
for
:
.
touchUpInside
)
//2
//2
//注册用户
//注册用户
...
@@ -26,41 +39,173 @@ class YHIMTestViewController: YHBaseViewController {
...
@@ -26,41 +39,173 @@ class YHIMTestViewController: YHBaseViewController {
// completion:^(NSString *aUsername, EMError *aError) {
// completion:^(NSString *aUsername, EMError *aError) {
// }];
// }];
EMClient
.
shared
()
.
register
(
withUsername
:
"davidTest"
,
password
:
"galaxy-666"
)
{
aUsername
,
error
in
// EMClient.shared().register(withUsername: "davidTest", password: "galaxy-666") { aUsername, error in
if
let
err
=
error
{
// if let err = error {
print
(
"注册失败"
)
// print("注册失败")
print
(
err
.
description
)
// print(err.description)
}
else
{
// } else {
print
(
"注册成功"
)
// print("注册成功")
//
//
// //登录账号
//// [[EMClient sharedClient] loginWithUsername:@"username"
//// password:@"your password"
//// completion:^(NSString *aUsername, EMError *aError) {
////
//// }];
//
// EMClient.shared().login(withUsername: "davidTest", password: "galaxy-666") { aUsername, error in
// if let err = error {
// print("登录失败")
// print(err.description)
// } else {
// print("登录成功")
//
//
//
// }
// }
// }
// }
EMClient
.
shared
()
.
roomManager
?
.
add
(
self
,
delegateQueue
:
nil
)
EMClient
.
shared
()
.
chatManager
?
.
add
(
self
,
delegateQueue
:
nil
)
EMClient
.
shared
()
.
login
(
withUsername
:
"1040217809134595"
,
token
:
"YWMtqUTnNKsxEe-ZVA-eCJXgmszPhuTA1UDqp8xrPJoVisk1wDGwqzER74uZ-bqVfmOVAwMAAAGTY4WtWgABUYBw0BfZJnoSM_kNt49EM81gKznPICMuPw-M2Fhj96-G7Q"
)
{
name
,
err
in
if
let
err
=
err
{
print
(
err
)
if
err
.
code
.
rawValue
==
200
{
EMClient
.
shared
()
.
roomManager
?
.
joinChatroom
(
"265249570750475"
,
ext
:
"nickname=DavidTest"
,
leaveOtherRooms
:
true
,
completion
:
{
room
,
err
in
if
let
err
=
err
{
print
(
"加入聊天室 - 失败"
)
print
(
err
)
}
else
{
print
(
"加入聊天室 - 成功"
)
}
})
}
else
{
print
(
"登录 - 失败"
)
}
}
else
{
print
(
"登录 - 成功"
)
//登录账号
// [[EMClient sharedClient] loginWithUsername:@"username"
// password:@"your password"
// completion:^(NSString *aUsername, EMError *aError) {
//
// }];
EMClient
.
shared
()
.
login
(
withUsername
:
"davidTest"
,
password
:
"galaxy-666"
)
{
aUsername
,
error
in
//发送消息
if
let
err
=
error
{
EMClient
.
shared
()
.
roomManager
?
.
joinChatroom
(
"265249570750475"
,
ext
:
"nickname=DavidTest"
,
leaveOtherRooms
:
true
,
completion
:
{
room
,
err
in
print
(
"登录失败"
)
print
(
err
.
description
)
if
let
err
=
err
{
print
(
"加入聊天室 - 失败"
)
print
(
err
)
}
else
{
}
else
{
print
(
"登录成功"
)
print
(
"加入聊天室 - 成功"
)
}
}
}
}
)
}
}
}
}
}
deinit
{
EMClient
.
shared
()
.
chatManager
?
.
remove
(
self
)
EMClient
.
shared
()
.
roomManager
?
.
remove
(
self
)
}
}
private
extension
YHIMTestViewController
{
@objc
func
sendMessage
()
{
getRoomInfo
()
// 调用 initWithText 创建文本消息。`content` 为文本消息的内容。
let
textMessageBody
=
EMTextMessageBody
(
text
:
"金龙发送的信息"
)
// 消息接收方,单聊为对端用户的 ID,群聊为群组 ID,聊天室为聊天室 ID。
let
conversationId
=
"265249570750475"
let
message
=
EMChatMessage
(
conversationID
:
conversationId
,
body
:
textMessageBody
,
ext
:
nil
)
// 会话类型,单聊为 `EMChatTypeChat`,群聊为 `EMChatTypeGroupChat`,聊天室为 `EMChatTypeChatRoom`,默认为单聊。
message
.
chatType
=
.
chatRoom
// 发送消息。
// EMClient.shared().chatManager?.sendMessage(message, progress: nil) { result in
// switch result {
// case .success:
// print("消息发送成功")
// case .failure(let error):
// print("消息发送失败: \(error.localizedDescription)")
// }
// }
EMClient
.
shared
()
.
chatManager
?
.
send
(
message
,
progress
:
nil
,
completion
:
{
message
,
error
in
if
let
err
=
error
{
printLog
(
"消息发送 --- 失败"
)
}
else
{
printLog
(
"消息发送 --- 成功"
)
//获取历史消息
let
option
=
EMFetchServerMessagesOption
();
EMClient
.
shared
()
.
chatManager
?
.
fetchMessagesFromServer
(
by
:
"265249570750475"
,
conversationType
:
.
chatRoom
,
cursor
:
""
,
pageSize
:
50
,
option
:
option
,
completion
:
{
result
,
err
in
if
let
err
=
err
{
// 获取失败
printLog
(
"获取历史消息 --- 失败"
)
printLog
(
err
)
}
else
{
// 获取成功
printLog
(
"获取历史消息 --- 成功"
)
printLog
(
result
)
}
})
}
})
}
func
getRoomInfo
()
{
EMClient
.
shared
()
.
roomManager
?
.
getChatroomSpecificationFromServer
(
withId
:
roomID
,
fetchMembers
:
true
,
completion
:
{
emChatRoom
,
err
in
printLog
(
emChatRoom
)
if
let
err
=
err
{
}
else
{
}
})
}
}
}
}
// 收到其他人加入聊天室的回调
extension
YHIMTestViewController
:
EMChatroomManagerDelegate
{
func
userDidJoin
(
_
aChatroom
:
EMChatroom
,
user
aUsername
:
String
,
ext
:
String
?)
{
printLog
(
aChatroom
)
printLog
(
aUsername
)
printLog
(
ext
)
}
func
userDidJoin
(
_
aChatroom
:
EMChatroom
,
user
aUsername
:
String
)
{
let
memberCount
=
aChatroom
.
occupantsCount
printLog
(
memberCount
)
}
func
userDidLeave
(
_
aChatroom
:
EMChatroom
,
user
aUsername
:
String
)
{
let
memberCount
=
aChatroom
.
occupantsCount
printLog
(
memberCount
)
}
}
extension
YHIMTestViewController
:
EMChatManagerDelegate
{
//收到消息
func
messagesDidReceive
(
_
aMessages
:
[
EMChatMessage
])
{
for
(
i
,
t
)
in
aMessages
.
enumerated
()
{
printLog
(
t
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment