'Cannot login to Agora RTM with Swift
So I am attempting to implement Agora RTM within my SwiftUI app. Below is the code I am using to attempt to log on but I keep getting error code 3. Any help would be greatly appreciated.
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)
}
})
}
}
}
}
I have tried setting the token parameter to nil to test and have guaranteed a fresh one when I have tested with one as above.
Solution 1:[1]
Ok this one was rather easy after all. Only certain characters are allowed for the user parameter string, and a character limit is also enforced. Changing to a more simple string corrected the issue (thanks Matt Frazer for you suggestion).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | riverbayMark |