-
Notifications
You must be signed in to change notification settings - Fork 11
/
apns.js
77 lines (59 loc) · 2.42 KB
/
apns.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var apn = require('apn');
const path = require('path');
var keyPath = path.join(__dirname, 'apns.p8');
console.log(keyPath);
var options = {
token: {
key: keyPath, // Path to the key p8 file
keyId: "N4L6HNZW6Q", // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/certificate/key)
teamId: "4SK4K45JGW" // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/)
},
production: false
};
function test (tokens) {
var apnProvider = new apn.Provider(options);
// Enter the device token from the Xcode console
// var deviceToken = '02ec1068812dd3b377010d86d253d87488a95b876920145467da299096bc9689';
// Prepare a new notification
var notification = new apn.Notification();
// Specify your iOS app's Bundle ID (accessible within the project editor)
notification.topic = 'com.lashou.StartupCycle.BusinessMembers';
// Set expiration to 1 hour from now (in case device is offline)
notification.expiry = Math.floor(Date.now() / 1000) + 3600;
// Set app badge indicator
notification.badge = 3;
// Play ping.aiff sound when the notification is received
notification.sound = 'ping.aiff';
// Display the following message (the actual notification text, supports emoji)
notification.alert = 'Hello World \u270C';
// Send any extra payload data with the notification which will be accessible to your app in didReceiveRemoteNotification
notification.payload = {id: 123};
// Actually send the notification
apnProvider.send(notification, tokens).then(function(result) {
// Check the result for any failed devices
console.log(result);
response.sent.forEach( (token) => {
// notificationSent(user, token);
});
response.failed.forEach( (failure) => {
if (failure.error) {
// A transport-level error occurred (e.g. network problem)
// notificationError(user, failure.device, failure.error);
} else {
// `failure.status` is the HTTP status code
// `failure.response` is the JSON payload
// notificationFailed(user, failure.device, failure.status, failure.response);
}
apnProvider.shutdown();
});
});
}
var a = function send () {
console.log('hello');
}
module.exports = {
push: function (tokens) {
return test(tokens);
},
send: a
};