I want to send voip push to my iOS app when its not active, and I tried to use apn module
from this solution but it did not work for me.
I followed official apple docs about voip push here but still have some problems to send it from the server.
I also tried to send it trough AWS sns service but got normal push for notification and etc.
What do I do wrong?
Right now my code is :
here I do format for sns item
const formatVoipPushNotificationsToSend = (type, header, launchId, sender, to = '', device_token, token) => {
const headers = {
':method': 'POST',
'apns-topic': '************.voip', //application bundle ID
':scheme': 'https',
':path': `/3/device/${device_token}`,
'authorization': `bearer ${token}`,
'apns-push-type': 'voip',
};
const aps = {
alert: {
title: header,
body: 'text' || null
},
itemId: type,
from: sender || null,
to,
launchId: launchId || null,
'content-available': 1
};
return { aps, headers };
};
and then I pass the item here and send it to the app with sns endpoint.
const pushNotifications = (item, arn, userId) => {
const payload = JSON.stringify(item);
const snsMessage = {};
snsMessage[SNS_PAYLOAD_KEY] = payload;
const params = {
Message: JSON.stringify(snsMessage),
TargetArn: arn,
MessageStructure: 'json'
};
const eventBody = item.aps.itemId ? {
[EVENT_TYPES.PUSH_SEND]: item.aps.itemId
} : {};
AmplitudeService.logEvent(EVENT_TYPES.PUSH_SEND, userId, eventBody);
return snsClient.publish(params).promise();
};
I'm using a slightly different approach:
var apn = require('apn');
const { v4: uuidv4 } = require('uuid');
const options = {
token: {
key: 'APNKey.p8',
keyId: 'S83SFJIE38',
teamId: 'JF982KSD6f'
},
production: false
};
var apnProvider = new apn.Provider(options);
// Sending the voip notification
let notification = new apn.Notification();
notification.body = "Hello there!";
notification.topic = "com.myapp.voip";
notification.payload = {
"aps": { "content-available": 1 },
"handle": "1111111",
"callerName": "Richard Feynman",
"uuid": uuidv4()
};
apnProvider.send(notification, deviceToken).then((response) => {
console.log(response);
});