Fazer uma ligação
Para fazer uma ligação, você utilizará o callButton no CallViewController Interface do usuário. Primeiro, você precisa atribuir um destino a ambos os botões.
class CallViewController: UIViewController {
...
override func viewDidLoad() {
...
self.client.delegate = self
hangUpButton.addTarget(self, action: #selector(endCall), for: .touchUpInside)
callButton.addTarget(self, action: #selector(makeCall), for: .touchUpInside)
}
}
Quando o callButton Quando for tocado, ele chamará o makeCall função. Adicione-a ao final do CallViewController classe.
class CallViewController: UIViewController {
...
@objc private func makeCall() {
setStatusLabelText("Calling \(user.callPartnerName)")
client.serverCall(["to": user.callPartnerName]) { error, callId in
if error == nil {
self.setHangUpButtonHidden(false)
self.callID = callId
} else {
self.setStatusLabelText(error?.localizedDescription)
}
}
}
}
Ao fazer a ligação, o callServer A função é chamada. Isso enviará as informações contidas no dicionário — neste caso, o nome de usuário do destinatário da chamada — para o seu servidor de webhook. Seu webhook responderá com um objeto de controle de chamada, informando à Vonage a quem conectar sua chamada.
NOTA: Além disso, certifique-se de que o servidor de webhook que você configurou nas etapas anteriores ainda esteja em funcionamento.
Imprensa Cmd + R para compilar e executar novamente. Agora você tem um aplicativo de chamadas em funcionamento! Para testá-lo, você pode executar o aplicativo em dois simuladores/dispositivos diferentes e fazer chamadas entre os dois usuários:

Webhooks
À medida que você prossegue com a chamada, por favor, mude para o terminal e observe o /voice/answer endpoint chamado para recuperar o NCCO:
NCCO request:
- caller: Bob
- callee: Alice
---
EVENT:
{
client_ref: 'F906B27D-2119-482F-A876-0E5354D555D3',
from: null,
to: 'Bob',
uuid: '8eaf4a3b-bed7-4316-88f1-fdee8ed34552',
conversation_uuid: 'CON-a5739d52-35f4-49e1-99c9-68ef9ef2529a',
status: 'started',
direction: 'inbound',
timestamp: '2021-03-26T13:47:14.624Z'
}
---
EVENT:
{
start_time: null,
headers: {},
client_reference: 'F906B27D-2119-482F-A876-0E5354D555D3',
rate: null,
from: null,
to: 'Bob',
uuid: '8eaf4a3b-bed7-4316-88f1-fdee8ed34552',
conversation_uuid: 'CON-a5739d52-35f4-49e1-99c9-68ef9ef2529a',
status: 'answered',
direction: 'inbound',
network: null,
timestamp: '2021-03-26T13:47:14.624Z'
}
---
EVENT:
{
from: 'Bob',
to: 'Alice',
uuid: '61935d7b-9290-4788-8439-1111ae7c9f24',
conversation_uuid: 'CON-a5739d52-35f4-49e1-99c9-68ef9ef2529a',
status: 'started',
direction: 'outbound',
timestamp: '2021-03-26T13:47:21.032Z'
}
---
EVENT:
{
start_time: null,
headers: {},
rate: null,
from: 'Bob',
to: 'Alice',
uuid: '61935d7b-9290-4788-8439-1111ae7c9f24',
conversation_uuid: 'CON-a5739d52-35f4-49e1-99c9-68ef9ef2529a',
status: 'answered',
direction: 'outbound',
network: null,
timestamp: '2021-03-26T13:47:21.032Z'
}
---
EVENT:
{
headers: {},
end_time: '2021-03-26T13:47:23.000Z',
uuid: '61935d7b-9290-4788-8439-1111ae7c9f24',
network: null,
duration: '3',
start_time: '2021-03-26T13:47:20.000Z',
rate: '0.00',
price: '0',
from: 'Bob',
to: 'Alice',
conversation_uuid: 'CON-a5739d52-35f4-49e1-99c9-68ef9ef2529a',
status: 'completed',
direction: 'outbound',
timestamp: '2021-03-26T13:47:23.709Z'
}
---
EVENT:
{
headers: {},
client_reference: 'F906B27D-2119-482F-A876-0E5354D555D3',
end_time: '2021-03-26T13:47:23.000Z',
uuid: '8eaf4a3b-bed7-4316-88f1-fdee8ed34552',
network: null,
duration: '9',
start_time: '2021-03-26T13:47:14.000Z',
rate: '0.00',
price: '0',
from: null,
to: 'Bob',
conversation_uuid: 'CON-a5739d52-35f4-49e1-99c9-68ef9ef2529a',
status: 'completed',
direction: 'inbound',
timestamp: '2021-03-26T13:47:23.762Z'
}
---
Fazendo uma chamada de voz de aplicativo para aplicativo
Você faz uma chamada de voz de um aplicativo iOS para outro aplicativo iOS