Skip to content

Instantly share code, notes, and snippets.

@zontan
Created September 9, 2020 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zontan/675537e6d1caf5c2577e79ed2f3d1299 to your computer and use it in GitHub Desktop.
Save zontan/675537e6d1caf5c2577e79ed2f3d1299 to your computer and use it in GitHub Desktop.
var agoraRtm: AgoraRtmKit?
var friendID: String?
var handle: AuthStateDidChangeListenerHandle?
var currentUser: User?
var messageList: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
agoraRtm = AgoraRtmKit(appId: "YOUR_AGORA_APP_ID", delegate: self)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "chatCell")
}
override func viewWillAppear(_ animated: Bool) {
handle = Auth.auth().addStateDidChangeListener { (auth, user) in
self.currentUser = user
if let username = user?.displayName, let friendName = self.friendID {
self.navigationItem.title = friendName
self.agoraRtm?.login(byToken: nil, user: username, completion: { (error) in
if error != .ok {
print("error logging in")
}
})
} else {
//Handle logout
}
}
}
override func viewWillDisappear(_ animated: Bool) {
if let handle = handle {
Auth.auth().removeStateDidChangeListener(handle)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment