-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapnsPushManager.js
37 lines (33 loc) · 1.11 KB
/
apnsPushManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var apn = require('apn');
var options = {
token: {
key: "./pushNotiCert/AuthKey_L72G5CA2L4.p8",
keyId: "L72G5CA2L4",
teamId: "JPMH34L85K"
},
production: false
};
var apnProvider = new apn.Provider(options);
module.exports = {
apnProvider: apnProvider,
createNewNotification() {
let note = new apn.Notification();
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge = 3;
note.sound = "ping.aiff";
note.alert = "\uD83D\uDCE7 \u2709 You have a new message";
note.payload = { 'messageFrom': 'John Appleseed' };
//Topic in apns means BundleID
note.topic = "<your-app-bundle-id>";
apnProvider.send(note, '89999999999999999').then( (result) => {
// see documentation for an explanation of result
if(result.failed.length>0)
{
console.log(result.failed[0].response)
console.log('Push apns fail')
}
}).catch(err=>{
console.log(err)
})
}
}