Skip to content

Commit d1e18c7

Browse files
authored
Merge pull request #6 from Sadia-Alauddin/setupIOSClient
fixed iOS client setup function
2 parents 6afd7c1 + 2e58622 commit d1e18c7

File tree

4 files changed

+18
-38
lines changed

4 files changed

+18
-38
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
/.idea
13
# Logs
24
logs
35
*.log

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ function onTransmissionError(ctx, client, errorCode, notificationObj, recipient)
1414
ctx.onTransmissionError(client, errorCode, notificationObj, recipient);
1515
}
1616

17-
Notification.prototype.setupIOSClient = function setupIOSClient(
18-
dev_key_path, dev_cert_path, prod_key_path, prod_cert_path, prod_pass_phrase, stg_pass_phrase) {
17+
Notification.prototype.setupIOSClient = function setupIOSClient(key, cert, pass_phrase, sandbox) {
1918
var self = this;
20-
self.clients.ios = new Ios(dev_key_path, dev_cert_path, prod_key_path, prod_cert_path, prod_pass_phrase, stg_pass_phrase);
19+
self.clients.ios = new Ios(key, cert, pass_phrase, sandbox);
2120
self.clients.ios.onTransmitted = function (client, notificationObj, recipient) {
2221
onTransmitted(self, client, notificationObj, recipient);
2322
};

lib/ios.js

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -217,31 +217,14 @@ var initApnFeedback = function initApnFeedback(ctx, options) {
217217
var initApnSend = function initApnSend(ctx) {
218218
//if apn connection is undefined (on the very first connect or may be drain or disconnect
219219
if (!ctx.apn_connection) {
220-
var options = {};
221-
if (global.Environment === "production") {
222-
options = {
223-
"key": ctx.apn.prod_key,
224-
"cert": ctx.apn.prod_cert,
225-
"interval": 43200,
226-
"batchFeedback": true,
227-
"production": true
228-
};
229-
if(ctx.apn.prod_pass_phrase) {
230-
options.passphrase = ctx.apn.prod_pass_phrase;
231-
}
232-
}
233-
else {
234-
options = {
235-
"key": ctx.apn.dev_key,
236-
"cert": ctx.apn.dev_cert,
237-
"interval": 43200,
238-
"batchFeedback": true,
239-
"production": false
240-
};
241-
if(ctx.apn.stg_pass_phrase) {
242-
options.passphrase = ctx.apn.stg_pass_phrase;
243-
}
244-
}
220+
var options = {
221+
"key": ctx.apn.key,
222+
"cert": ctx.apn.cert,
223+
"interval": 43200,
224+
"batchFeedback": true,
225+
"production": ctx.apn.sandbox,
226+
"passphrase": ctx.apn.pass_phrase
227+
};
245228
ctx.apn_connection = new Apn.Connection(options);
246229
ctx.apn_connection.on("transmissionError", function(errorCode, notification, recipient) {
247230
onTransmissionError(ctx, errorCode, notification, recipient);
@@ -360,14 +343,12 @@ function push(ctx, tokens, payload) {
360343
* @returns {*}
361344
* @version 0.1
362345
*/
363-
function Ios(dev_key_path, dev_cert_path, prod_key_path, prod_cert_path, prod_pass_phrase, stg_pass_phrase) {
346+
function Ios(key, cert, pass_phrase, sandbox) {
364347
this.apn = {
365-
prod_key: prod_key_path,
366-
prod_cert: prod_cert_path,
367-
dev_key: dev_key_path,
368-
dev_cert: dev_cert_path,
369-
prod_pass_phrase: prod_pass_phrase,
370-
stg_pass_phrase: stg_pass_phrase
348+
key: key,
349+
cert: cert,
350+
pass_phrase: pass_phrase,
351+
sandbox: sandbox
371352
};
372353
}
373354

tests/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ describe("Notification", function() {
1313
global.RootPath = path.resolve("");
1414
var key = global.RootPath + "/tests/assets/key.pem";
1515
var cert = global.RootPath + "/tests/assets/cert.pem";
16-
var prodPassPhrase = "";
17-
var stgPassPhrase = "";
18-
notification.setupIOSClient(key,cert,key,cert,prodPassPhrase,stgPassPhrase);
16+
notification.setupIOSClient(key, cert, "", false);
1917
var apiKey = "please you api key here";
2018
notification.setupAndroidClient(apiKey);
2119

0 commit comments

Comments
 (0)