所以我试图在我的SwiftUI应用程序中实现Agora RTM。下面是我用来尝试登录的代码,但我一直得到错误代码3。如有任何帮助,我将不胜感激。
class AgoraChatOO: NSObject, ObservableObject {
@Published var chatMessages: [ChatMessage] = []
@Published var kit: AgoraRtmKit?
@Published var rtmChannel: AgoraRtmChannel?
func updateKit(appId: String, delegate: AgoraRtmDelegate, channelDelegate: AgoraRtmChannelDelegate) {
kit = AgoraRtmKit(appId: appId, delegate: delegate)
guard let kit = kit else { return }
print(kit)
print(delegate)
print(channelDelegate)
kit.login(byToken: "my temp token", user: UIDevice.current.name) { [unowned self] (error) in
if error != .ok {
print("Error logging in: ", error.rawValue)
} else {
self.rtmChannel = kit.createChannel(withId: "testChannel", delegate: channelDelegate) //This is the AgoraRtmChannelDelegate, which must be set to get messageReceived, memberLeft, and memberJoined callbacks.
self.rtmChannel?.join(completion: { (error) in
if error != .channelErrorOk {
print("Error joining channel: ", error.rawValue)
}
})
}
}
}
}
我已经尝试将token参数设置为nil来测试,并且当我使用上面的一个参数进行测试时,保证了一个新的token。
好吧,这毕竟很简单。用户参数字符串只允许某些字符,并且还强制执行字符限制。更改为更简单的字符串纠正了这个问题(感谢Matt Frazer的建议)。
如果您正在尝试运行演示项目:
- 请将uid更改为简单字符串(例如:'123')2.尝试运行您的项目,如果它显示错误代码5,那么尝试在agora中创建一个新项目,如以下链接所述:
https://github.com/AgoraIO/RTM/issues/58 issuecomment - 609409392
不要忘记将agora应用id替换为新的应用id。