Swift
電話をかける
電話をかけるには callButton での CallViewController UI。まず、両方のボタンにターゲットを追加する必要がある。
コピー
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)
}
}
そのとき callButton がタップされると makeCall 関数を使用する。この関数を CallViewController クラスである。
コピー
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)
}
}
}
}
電話をかける際 callServer 関数が呼び出されます。この関数は、辞書内の情報(この場合は着信側のユーザー名)をWebhookサーバーに渡します。あなたのWebhookは、Vonageにあなたのコールを誰に接続するかを伝えるコールコントロールオブジェクトで返信します。
注: また、前のステップで構築したウェブフック・サーバーがまだ稼働していることを確認してください。
プレス Cmd + R をビルドして再び実行する。これで通話アプリが機能するようになりました!試しに、2つの異なるシミュレーター/デバイスでアプリを実行し、2人のユーザー間で通話をしてみてください:

ウェブフック
通話を続けながら、端末に切り替えてください。 /voice/answer 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'
}
---