Swift
Sending a message
In the previous step you learned about conversations and events, sending a message creates a new event and sends it via the conversation.
To send a message, add the following function to ChatViewController.swift:
class ChatViewController: UIViewController {
...
func send(message: String) {
inputField.isEnabled = false
conversation?.sendMessage(NXMMessage(text: message), completionHandler: { [weak self] (error) in
DispatchQueue.main.async { [weak self] in
self?.inputField.isEnabled = true
}
})
}
}
To get the text from the inputField you need to add another function provided by the UITextFieldDelegate. Add the following function to the UITextFieldDelegate extension:
extension ChatViewController: UITextFieldDelegate {
...
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if let text = textField.text {
send(message: text)
}
textField.text = ""
textField.resignFirstResponder()
return true
}
}
This delegate function is called when the return button on the keyboard is pressed.
Build and Run
Cmd + R to build and run again. You now have a functioning chat app! To chat simultaneously you can run the app on two different simulators/devices:

Creating an iOS chat app
Create a iOS application that enables users to message each other
Steps
1
Introduction to this task2
Prerequisites3
Create a Vonage Application4
Create a conversation5
Create the users6
Add users to the conversation7
Generate JWTs8
Xcode project and workspace9
Building the log in interface10
Building the user model11
NXMClient12
Building the chat interface13
Chat events14
Sending a message15
What's next?