Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sending MDM push notification to APNS #38

Open
VenkateshSrini opened this issue Feb 1, 2016 · 0 comments
Open

sending MDM push notification to APNS #38

VenkateshSrini opened this issue Feb 1, 2016 · 0 comments

Comments

@VenkateshSrini
Copy link

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');
}
});
/**

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant