我正在 swiftui 应用程序中实现 Cometchat 和 Agora 音频聊天,在这两种情况下,我都面临着对我来说并不典型的情况。
直到某个方法一切正常,但在调用“加入频道”或“获取消息列表”的情况下,回调方法不起作用,虽然没有错误。
我附上了一个代码示例(一切都在方法之前有效,在回调内部却没有)。我不明白如何解决它。你能告诉我在哪个方向寻找解决方案吗?
print("DEBUG channelName", self.channelName, "uid", self.rtcId, "token", token) // works here
self.rtckit.joinChannel(byToken: token, channelId: self.channelName, info: nil, uid: self.rtcId) { (channel, uid, errCode) in
print("DEBUG Inside AgoraObservable rtckit.joinChannel()") // Doesn't work here
self.rtcId = uid
self.channel = self.rtmkit?.createChannel(withId: self.channelName, delegate: self)
self.channel?.join(completion: { joinStatus in
print("DEBUG Inside self.channel?.join")
if joinStatus == .channelErrorOk {
let user = AgoraUserData(rtmId: self.rtmId, rtcId: self.rtcId, username: self.username)
guard let jsonString = try? user.toJSONString() else {
return
}
self.membersLookup[user.rtmId] = (user.rtcId, user.username)
self.channel?.send(AgoraRtmMessage(text: jsonString))
} else {
self.channel = nil
}
})
}
和
// Works here
messagesRequest.fetchPrevious(onSuccess: { (messages) in
// Doesn't work here
for message in messages!{
if let receivedMessage = (message as ? TextMessage) {
print("Message received successfully. " + receivedMessage.stringValue())
}
else if let receivedMessage = (message as ? MediaMessage) {
print("Message received successfully. " + receivedMessage!.stringValue())
}
}
}) { (error) in
print("Message receiving failed with error: " + error!.errorDescription);
}