Agora RTM login failed

823 views Asked by At

connection changed to connected connecting, because login login failed: AgoraRtmLoginErrorCode connection changed to connected disconnected, because loginFailure

func setupRTM() {
        self.agoraRTM = AgoraRtmKit(
            appId: "<#Agora App Id#>",
            delegate: self
        )
        print("logging in as \(UIDevice.current.name)")
        self.agoraRTM.login(
            byToken: nil, user: UIDevice.current.name,
            completion: self.rtmLoginCallback
        )
    }

    func rtmLoginCallback(_ err: AgoraRtmLoginErrorCode) {
        if err != .ok {
            print("login failed: \(err)")
        } else {
            print("login success")
            self.createAndJoin(channel: self.lobbyChannelName) { channel in
                self.lobbyChannel = channel
            }
        }
    }
2

There are 2 answers

0
Joice George On

You have to give an RTM token to log in. self.agoraRTM.login(byToken: nil), the token should not be nil.

Hope this link may help you:
https://docs.agora.io/en/signaling/get-started/get-started-sdk?platform=ios#1-set-your-signing-and-team

0
maxxfrazer On

It could be that your UIDevice.current.name holds characters that are not allowed by default as the username for RTM. I tend to use identifierForVendor converted to a string, and then pass the UIDevice.current.name as a message telling everyone in the channel that it's my username. Especially as many people simply have "iPhone" as their device name, which would of course not be unique.

Permitted characters are mentioned in the API Ref here.

If that doesn't fix it, check the value of AgoraRtmLoginErrorCode. If it's .invalidArgument, then it will likely be the username that's being used.