0
I am using node-apn version 2.2.0 and am getting an error that I did not find in their github issues' list. Here is the exception trace:
pushMessage: '123' } at for_IOS_push (/home/ubuntu/Office-Curry-Server/Office-Curry-Backend/application/controller-service-layer/services/PushNotificationServiceV12.js:254:12)
[2019-05-07 09:43:15] ERROR Tue, 07 May 2019 09:43:15 GMT uncaughtException: this.getStream(...).then(...).catch is not a function at (/home/ubuntu/Office-Curry-Server/Office-Curry-Backend/configurations/Bootstrap.js:129:15)
[2019-05-07 09:43:15] ERROR TypeError: this.getStream(...).then(...).catch is not a function
at Client.write (/home/ubuntu/Office-Curry-Server/Office-Curry-Backend/node_modules/apn/lib/client.js:114:13)
at Promise.all.recipients.map.token (/home/ubuntu/Office-Curry-Server/Office-Curry-Backend/node_modules/apn/lib/provider.js:29:62)
at Array.map ()
at Provider.send (/home/ubuntu/Office-Curry-Server/Office-Curry-Backend/node_modules/apn/lib/provider.js:29:36)
at for_IOS_push (/home/ubuntu/Office-Curry-Server/Office-Curry-Backend/application/controller-service-layer/services/PushNotificationServiceV12.js:304:17)
at /home/ubuntu/Office-Curry-Server/Office-Curry-Backend/application/controller-service-layer/services/PushNotificationServiceV12.js:455:29
at /home/ubuntu/Office-Curry-Server/Office-Curry-Backend/node_modules/async/lib/async.js:52:16
at /home/ubuntu/Office-Curry-Server/Office-Curry-Backend/node_modules/async/lib/async.js:527:17
at /home/ubuntu/Office-Curry-Server/Office-Curry-Backend/node_modules/async/lib/async.js
I am using node version 9.2.1.
Here are the options that I initialize the provider with:
{"token":
{"key":"/home/ubuntu/Office-Curry-Server/Office-Curry-Backend/certificate/AuthKey_4F29WHN247.p8",
"keyId":"4F29WHN247",
"teamId":"8E3M5LT2S6"},
"production":false}
DeviceId, I checked, is also valid. I get this error right when I call apnProvider.send().then() and the error comes from the file "client.js" inside node_modules/apn/lib.
Here is the node-javascript code:
var for_IOS_push = function(devices, unread_count, groupType, apnProvider, isSilentPush, pushInfo, postDetails, next) {
var myDevice = devices[0];
console.log("Sending notification to device ID: ", myDevice);
var note = new apn.Notification();
note.expiry = Math.round(new Date().getTime() / 1000) + 3600; // Expires 1 hour from now.
note.badge = unread_count;
note.topic = "com.officecurry";
// note.category = groupType;
//note.groupType = groupType;
isSilentPush == true ? note.sound = "" : note.sound = "ocy_notification_sound.caf";
note.payload = {};
Logger.info("----------------- Sending Push Notification -----------------", pushInfo);
if (pushInfo.pushMessage != undefined) {
pushInfo.pushMessage = pushInfo.pushMessage.replace("<b>", "");
pushInfo.pushMessage = pushInfo.pushMessage.replace("</b>", "");
}
if (pushInfo.InappMessage != undefined) {
pushInfo.InappMessage = pushInfo.InappMessage.replace("<b>", "");
pushInfo.InappMessage = pushInfo.InappMessage.replace("</b>", "");
}
var a = {
title: pushInfo.pushHeader,
body: pushInfo.pushMessage
};
note.alert = a;
if (groupType && groupType.type != "privateMessage") {
note.payload = {
'notificationId': postDetails.parent_post_id,
'messageFrom': "Office Curry",
'type': groupType.type,
'update': postDetails.last_update,
'unread_count': unread_count,
'postId': postDetails.parent_post_id,
};
if (groupType.action) note.payload.action = groupType.action;
if (groupType.related_post) note.payload.related_post = postDetails.parent_post_id;
} else if (groupType && groupType.type == "privateMessage") {
note.payload = {
'notificationId': postDetails.parent_post_id,
'messageFrom': "Office Curry",
'pid': postDetails.parent_post_id,
'type': groupType.type,
'msgData': groupType.message,
'user': groupType.originator._id,
'imgMessage': groupType.image_msg,
'msg_type': groupType.originator.msg_type,
'last_update': postDetails.last_update,
'userImage': groupType.originator.profile_image,
};
}
note.payload.InappMessage = pushInfo.InappMessage;
apnProvider.send(note, myDevice).then((response) => {
response.sent.forEach((token) => {
Logger.info("Notification successfully sent for token: " + token);
});
response.failed.forEach((failure) => {
if (failure.error) {
// A transport-level error occurred (e.g. network problem)
Logger.info("Transport level failure: Device: " + failure.device + ", Error: " + failure.error);
} else {
// `failure.status` is the HTTP status code
// `failure.response` is the JSON payload
Logger.info("Other failure: Device: " + failure.device + ", Status: " + failure.status + ", Response: " + failure.response);
}
});
});
}