ios - 请求 APNs VoIP 通知 (Flutter iOS)

标签 ios flutter apple-push-notifications voip http2

我正在开发一个消息应用程序,该应用程序目前使用带有 Firebase 功能的 FCM 来推送通知。 对于 VoIP 服务,我使用 Agora,但我想将原生外观添加到我的应用程序中,在用户接听电话时添加 CallKit 布局。 我正在使用 flutter_ios_voip_kit,并且我在终端中使用curl 命令正确地获取了 VoIP 通知。

curl -v \
-d '{"aps":{"alert":{"uuid":"982cf533-7b1b-4cf6-a6e0-004aab68c503","incoming_caller_id":"0123456789","incoming_caller_name":"Tester"}}}' \
-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>

但我真的不知道如何在我的应用程序上实现该请求。 我想将其保留在客户端,因此当用户点击调用按钮时,我尝试运行 http.post 调用,但它不起作用(我不知道这是格式错误还是其他原因)。

final url =
      'https://api.sandbox.push.apple.com:443/3/device/*myDeviceVoIPToken*';
  //final uuid = Uuid().v4();
  final Map body = {
    "aps": {
      "alert": {
        "uuid": "${Uuid().v4()}",
        "incoming_caller_id": "0123456789",
        "incoming_caller_name": "Tester"
      }
    }
  };
  Future<http.Response> postRequest() async {
    return await http.post(url,
        headers: <String, String>{
          'apns-push-type': 'voip',
          'apns-expiration': '0',
          'apns-priority': '0',
          'apns-topic': '*myBundleId*.voip'
        },
        body: jsonEncode(body));

我也尝试使用 http2 ,但没有运气。 您能给出使用 http.post 请求 VoIP 通知的代码示例吗?或者随时提出更好的选择。 谢谢。

最佳答案

问题是您没有使用 voip 证书来验证您的 HTTP 请求。通过 --cert 命令查看您是否在curl 请求中使用了它。 我不知道如何使用 http.post 执行此操作,但您需要证书的私钥才能使用它来签署您的请求。 https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_certificate-based_connection_to_apns

但是,您不应该通过应用程序发送推送,因为这意味着您需要将 voip 证书私钥与应用程序打包在一起。通过某种逆向工程,任何人都可以获取您的私钥,并向您的应用程序发送推送。私钥应该安全地保存在您的服务器内,并且永远不要像您计划的那样共享。

关于ios - 请求 APNs VoIP 通知 (Flutter iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63953426/

相关文章:

ios - 如何将 DataResponse<Any> 转换为 DefaultDataResponse

ios - 以编程方式检测从哪个应用商店下载了该应用

flutter - 如何为到达页面后的窗口小部件树中的所有窗口小部件提供身份验证证书,并使导航器仍在工作

flutter - 如何 catch 文本字段小部件上的打字速度?

ios - 如何在 iOS 中触发 didReceiveRemoteNotification?

ios - NSUserDefaults 不会在导航时保存

flutter - 乌克兰移动应用支付网关

ios - 请求多个权限

ios - 需要指导在 Cordova 应用程序中使用 native APNs/GCM 为 iOS 推送通知

iphone - 用户单击 "assistance"图标后模式文本弹出的最佳方法?