你的问题:你能告诉我当应用程序在后台或被杀死时你是如何显示来电的吗?
我还在使用 React Native Callkeep 和 Twilio 进行视频通话。
找到解决方案
这对我们适用于 iOS 和 Android,即使应用被用户明确杀死。
使用-
- https://github.com/zo0r/react-native-push-notification
-
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,
]);