这对我有用!不要忘记在您的目录中添加 Authkey_xxxx.p8 文件,并且不要忘记在通知主题中将 .voip 添加到您的包 ID。
export const test = functions.https.onRequest((request, response) => {
const config = {
production: false, /* change this when in production */
token: {
key: "./AuthKey_xxxx.p8",
keyId: "xxxx",
teamId: "yyyy"
}
};
const apnProvider = new apn.Provider(config);
const notification = new apn.Notification();
const recepients: string[] = [];
recepients.push(apn.token('SOME PUSHKIT TOKEN'));
recepients.push(apn.token('ANOTHER PUSHKIT TOKEN'));
notification.topic = 'com.your.app.voip'; // you have to add the .voip here!!
notification.payload = {
// some payload
};
return apnProvider.send(notification, recepients).then((reponse) => {
console.log(reponse);
return response.send("finished!");
});
});