Place a call
At the top of the ViewController class, right below the client declaration, add a NXMCall property to hold a reference to any call in progress
class ViewController: UIViewController, NXMClientDelegate {
...
let client = NXMClient.shared
var call: NXMCall?
...
}
Based on the object referenced by the call property, the callButtonPressed method can now be used to either place or end calls; the placeCall and endCall methods are triggered for each case.
Replace the current callButtonPressed method with the code below:
@IBAction func callButtonPressed(_ sender: Any) {
if call == nil {
placeCall()
} else {
endCall()
}
}
func placeCall() {
callButton.setTitle("End Call", for: .normal)
client.serverCall(withCallee: "PHONE_NUMBER", customData: nil) { [weak self] (error, call) in
if let error = error {
self?.connectionStatusLabel.text = error.localizedDescription
self?.callButton.setTitle("Call", for: .normal)
}
self?.call = call
}
}
func endCall() {
call?.hangup()
call = nil
callButton.setTitle("Call", for: .normal)
}
NOTE: Please make sure to replace PHONE_NUMBER below with the actual phone number you want to call, in the E.164 format (for example, 447700900000).
NOTE: Also, please make sure that the webhook server you built in the previous steps is still running.
That's it! You can now build, run and place the call! Magic!
Once the call comes through you can answer it and hear the in-app voice call.
Webhooks
As you proceed with placing the call, please switch to the terminal and notice the /voice/answer endpoint being called to retrieve the NCCO:
Also, as the call progresses through various stages, /voice/event is being sent events:
NOTE: As the call is completed, events will also contain duration and pricing information.
Making an in-app voice call
You make a voice call from an iOS app to a phone.