ios_callkit
使用CallKit和PushKit在Flutter iOS应用中进行一对一视频通话。
动机
我们需要使用CallKit来处理iOS 13及以上版本的VoIP来电通知。 请参阅WWDC2019视频了解更多信息。因此,除了单独使用CallKit和PushKit之外,将它们结合起来使用的需求也日益增长。然而,网络上关于同时使用CallKit和PushKit的VoIP通知示例(尤其是针对Flutter)仍然很少。我决定创建一个具有最少必需功能的Flutter插件。您可以使用此插件,但实际目的是帮助您创建适合您服务的VoIPKit。
要求
- 仅支持iOS,不支持Android。
- 需要iOS 10或更高版本。
- 仅支持一对一通话,不支持群组通话。
- 需要一个服务器来通过APNs推送VoIP通知。
- 要实际进行视频通话或语音通话,您需要链接到WebRTC服务(例如:Agora、SkyWay、Amazon Kinesis Video Streams)。
用法
1. 安装
- 在您的pubspec.yaml文件中将
ios_callkit添加为依赖项。
2. 在Xcode中设置能力
- 选择“后台模式” > “VoIP”和“远程通知”为“开启”。
- 选择“推送通知”。
- 选择能力后修改
ios/Runner/Info.plist。
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
<string>voip</string>
</array>
2. 编辑Info.plist
- 按以下方式编辑
ios/Runner/Info.plist。
<key>FIVKIconName</key>
<string>AppIcon-VoIPKit</string>
<key>FIVKLocalizedName</key>
<string>VoIP-Kit</string>
<key>FIVKSupportVideo</key>
<true/>
<key>FIVKSkipRecallScreen</key>
<true/>
3. 为CallKit添加新的图像集
- 添加一个图标(.png或.pdf)到
ios/Runner/Assets.xcassets/AppIcon-VoIPKit,用于在iPhone锁屏状态下接收来电时显示。
4. 创建VoIP服务证书
- 访问Apple Developer https://developer.apple.com/certificates,创建一个新的VoIP服务证书(
.cer)。 请参阅“Voice Over IP (VoIP)最佳实践”图11-2了解更多信息。 - 使用KeyChainAccess从
.cer创建.p12,并使用openssl创建.pem。
使用KeyChainAccess从.cer创建.p12 |
|---|
![]() |
openssl pkcs12 -in voip_services.p12 -out voip_services.pem -nodes -clcerts
5. 从您的服务器请求VoIP通知APNs
- 请参阅Apple文档。
- https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
- 添加如下所示的数据(payload)。
{
"aps": {
"alert": {
"uuid": <Version 4 UUID (e.g.: https://www.uuidgenerator.net/version4) >,
"incoming_caller_id": <your service user id>,
"incoming_caller_name": <your service user name>,
}
}
}
- 您可以使用curl按如下方式测试VoIP通知。
curl -v \
-d '{"aps":{"alert":{"uuid":"982cf533-7b1b-4cf6-a6e0-004aab68c503","incoming_caller_id":"0123456789","incoming_caller_name":"Tester","videoType":true}}}' \
-H "apns-push-type: voip" \
-H "apns-expiration: 0" \
-H "apns-priority: 0" \
-H "apns-topic: <your app’s bundle ID>.voip" \
--http2 \
--cert ./voip_services.pem \
https://api.sandbox.push.apple.com/3/device/<VoIP device Token for your iPhone>
