Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to login via SwiftUI app #4

Closed
riverbaymark opened this issue Apr 17, 2022 · 2 comments
Closed

Not able to login via SwiftUI app #4

riverbaymark opened this issue Apr 17, 2022 · 2 comments

Comments

@riverbaymark
Copy link

I have been trying to implement RTM in a SwiftUI app but it keeps giving me an error code 3. Below is the code I am currently using (I instantiate the class as a @StateObject and pass the instance back to represent the rtm and channel delegates)..

`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 }
     
    kit.login(byToken: "my_tokeni", 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)
                
                self.rtmChannel?.join(completion: { (error) in
                    if error != .channelErrorOk {
                        print("Error joining channel: ", error.rawValue)
                    }
                })
            }
        }
    }

}`

@maxxfrazer
Copy link
Contributor

Login error code 3 means that there's an invalid parameter. It's likely either the appId or UIDevice.current.name.

Could you print out what that UIDevice name is? Not all characters are allowed there, and there's a limit of 64 bytes:
https://docs.agora.io/en/Real-time-Messaging/API%20Reference/RTM_oc/Classes/AgoraRtmKit.html#//api/name/loginByToken:user:completion:

@riverbaymark
Copy link
Author

Hi @maxxfrazer you were absolutely correct..I changed it to a different string and it worked. Did have a couple of other issues pop up though. I could not get it to logon using a token, but was able to with a nil token using a different AppId. The other issue now is the delegate methods are not being called after sending a message to the channel. Would it be possible for you to create a simple SwiftUI demo for RTM (sorry I know it's a big ask). Also wanted to say I'm a big fan of your Agora and RealityKit tutorials and articles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants