Im developing a messaging application, which, right now uses FCM with Firebase functions to push notifications. For the VoIP service I am using Agora, but I want to add that native look to my application adding CallKit layouts when a user receive a call. Im using flutter_ios_voip_kit and I'm correctly getting the VoIP notification using the curl command in the terminal.
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>
But I don't really know how to implement that request on my application. I want to keep it client side, so when a user tap on the call button I tried to run http.post call, but it does not work (I don't know if it's for a format mistake or something else).
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));
I also tried to use http2, but without luck. Can you give a code example of request VoIP notification using http.post? Or feel free to suggest better options. Thank you.
The problem is that you are not using the voip certificate to authenticate your HTTP request. See that you are using that on your curl request with the --cert command. I don't know how to do that with http.post, but you need the private key of the certificate to use it to sign your request. https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_certificate-based_connection_to_apns
However, you should not be sending pushes through your app, because it means you will need to pack your voip certificate private key with your application. With some sort of reverse engineering anyone can get your private key, and send pushes to your apps. The private key should be kept safe inside your server, and never be shared as your are planning to do.