You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm trying send a MDM push notification to the APNS server. My connection is successful and sending of notification is successful. Unfortunately APNS is not delivering the notification to the device instead it is reported in feedback service. Below is the code I used
var apnAgent = require('apnagent'),
fs = require('fs');
var agent = new apnAgent.Agent();
var tokenBuff = new Buffer("", 'base64'); //device Token
var cert = fs.readFileSync('./certificates/newCrt.pem');
var key = fs.readFileSync('./certificates/newKey.pem');
var tokenHex = tokenBuff.toString('hex');
var settings = {
"device": tokenHex,
"pushMagic":"push magic token",
"auth": {
"cert": cert,
"key": key
}
agent.connect(function (err) {
// gracefully handle auth problems
if ((err != null) && (err.name === 'GatewayAuthorizationError')) {
console.log('Authentication Error: %s', err.message);
process.exit(1);
}
// handle any other err (not likely)
else if (err) {
throw err;
}
else {
console.log('connect to APNS');
}
});
/**
Listen for send errors
*/
agent.on('message:error', function (err, msg) {
switch (err.name) {
case 'GatewayMessageError':
console.log('[emitted] gw notification error: %s', err.message);
if (err.code === 8) {
console.log(' > %s', msg.device().toString());
}
break;
case 'MessageSerializationError':
console.log('[emitted] serialization error: %s', err.message);
break;
default:
console.log('[emitted] other error: %s', err.message);
break;
}
//if (!err) {
// console.log("Message is " + msg);
//}
});
var msg = agent.createMessage()
msg.device(tokenHex);
msg.set('mdm', settings.pushMagic);
msg.send(function (err) {
if (err) console.log('[cb] serialization error: %s', err.message);
});
The resultant Payload that is sent to server is using apnagent is
{"deviceToken":{"type":"Buffer","data":[]},"expiration":0,"identifier":0,"payload":{"mdm":"","aps":{}}}
Please help.
Thanks and regards
Venkatesh
The text was updated successfully, but these errors were encountered:
Hi,
I'm trying send a MDM push notification to the APNS server. My connection is successful and sending of notification is successful. Unfortunately APNS is not delivering the notification to the device instead it is reported in feedback service. Below is the code I used
var apnAgent = require('apnagent'),
fs = require('fs');
var agent = new apnAgent.Agent();
var tokenBuff = new Buffer("", 'base64'); //device Token
var cert = fs.readFileSync('./certificates/newCrt.pem');
var key = fs.readFileSync('./certificates/newKey.pem');
var tokenHex = tokenBuff.toString('hex');
var settings = {
"device": tokenHex,
"pushMagic":"push magic token",
"auth": {
"cert": cert,
"key": key
}
};
agent.gateway = 'gateway.push.apple.com'
agent.set(settings.auth);
agent.connect(function (err) {
// gracefully handle auth problems
if ((err != null) && (err.name === 'GatewayAuthorizationError')) {
console.log('Authentication Error: %s', err.message);
process.exit(1);
}
// handle any other err (not likely)
else if (err) {
throw err;
}
else {
console.log('connect to APNS');
}
});
/**
agent.on('message:error', function (err, msg) {
switch (err.name) {
case 'GatewayMessageError':
console.log('[emitted] gw notification error: %s', err.message);
if (err.code === 8) {
console.log(' > %s', msg.device().toString());
});
var msg = agent.createMessage()
msg.device(tokenHex);
msg.set('mdm', settings.pushMagic);
msg.send(function (err) {
if (err) console.log('[cb] serialization error: %s', err.message);
});
The resultant Payload that is sent to server is using apnagent is
{"deviceToken":{"type":"Buffer","data":[]},"expiration":0,"identifier":0,"payload":{"mdm":"","aps":{}}}
Please help.
Thanks and regards
Venkatesh
The text was updated successfully, but these errors were encountered: