【问题标题】:Incoming audio/video call with call keep when phone is locked or app is killed当手机被锁定或应用程序被杀死时,来电音频/视频通话并保持通话
【发布时间】:2021-05-25 09:21:38
【问题描述】:

React Native Callkeep 与 Twilio: 案例 1 - 带有原生 UI(Callkeep)的应用程序打开(前台)音频-视频通话工作正常 案例 2 - 带有原生 UI(Callkeep)的应用程序打开(后台)音频视频通话工作正常 案例 3 - 应用关闭(Kill 状态)音视频通话不带有本机 UI(Callkeep)不工作 案例 4 - 应用打开电话锁定音频视频通话,带有本机 UI(Callkeep)工作正常但是当接听电话时,本机通话 UI 出现在屏幕上,手机无法解锁,也无法加载我们的应用

【问题讨论】:

    标签: android ios react-native


    【解决方案1】:

    你的问题:你能告诉我当应用程序在后台或被杀死时你是如何显示来电的吗?

    我还在使用 React Native Callkeep 和 Twilio 进行视频通话。

    找到解决方案

    这对我们适用于 iOS 和 Android,即使应用被用户明确杀死。

    使用-

    1. https://github.com/zo0r/react-native-push-notification
    2. https://github.com/react-native-push-notification-ios/push-notification-ios (完成这两个软件包所需的完整设置)

    APN 请求

    $url = "https://api.sandbox.push.apple.com/3/device/<device_token>";
    $headers = array(
        "apns-push-type: voip",
        "apns-expiration: 10",
        "apns-topic: com.example.app.voip", // .voip as suffix to bundleID
        "apns-collapse-id: lcall", 
        "Content-Type: application/x-www-form-urlencoded",
    );
    $certificate_file = config('pushnotification.apn.certificate');
    $payloadArray['aps'] = [
        'alert' => [
            'title' => "Calling title",
            'body' => "Calling body",
        ],
        'badge' => 1,
        "content-available" => 1
    ];
    $data = json_encode($payloadArray);
    $client = new Client();
    $response = $client->post($url, [
        'headers' => $headers,
        'cert' => $certificate_file,
        'curl' => [
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
        ],
        'body'=> $data,
    ]);
    

    阅读官方apns-push-type- https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns

    FCM 请求

    $url = "https://fcm.googleapis.com/fcm/send";
    $headers = array(
        'Authorization' => 'key=<fcm_server_key',
        'Content-Type' => 'application/json'
    );
    $payloadArray = [
        "to" => "<device_token>",
        "data" => [
            "title"=> "Calling Title",
            "body" => "Calling Body",
        ]
    ];
    $data = json_encode($payloadArray);
    $client = new Client();
    $response = $client->post($url, [
        'headers' => $headers,
        'curl' => [
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        ],
        'body'=> $data,
    ]);
    

    【讨论】:

    • 我们刚刚处理了 in-app 和应用在 background 中的两种情况。
    • 应用在后台时你是怎么处理的?使用 react-native-push-notification 包的 Silent 远程推送通知?
    猜你喜欢
    • 1970-01-01
    • 2022-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多