|
1 |
| - |
2 | 1 | var PushNotification = function() {
|
3 | 2 | };
|
4 | 3 |
|
| 4 | +// Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android) |
| 5 | +PushNotification.prototype.register = function(successCallback, errorCallback, options) { |
| 6 | + if (errorCallback == null) { errorCallback = function() {}} |
| 7 | + |
| 8 | + if (typeof errorCallback != "function") { |
| 9 | + console.log("PushNotification.register failure: failure parameter not a function"); |
| 10 | + return |
| 11 | + } |
| 12 | + |
| 13 | + if (typeof successCallback != "function") { |
| 14 | + console.log("PushNotification.register failure: success callback parameter must be a function"); |
| 15 | + return |
| 16 | + } |
| 17 | + |
| 18 | + cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]); |
| 19 | +}; |
5 | 20 |
|
6 |
| - // Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android) |
7 |
| - PushNotification.prototype.register = function(successCallback, errorCallback, options) { |
8 |
| - if (errorCallback == null) { errorCallback = function() {}} |
| 21 | +// Call this to unregister for push notifications |
| 22 | +PushNotification.prototype.unregister = function(successCallback, errorCallback, options) { |
| 23 | + if (errorCallback == null) { errorCallback = function() {}} |
9 | 24 |
|
10 |
| - if (typeof errorCallback != "function") { |
11 |
| - console.log("PushNotification.register failure: failure parameter not a function"); |
12 |
| - return; |
13 |
| - } |
| 25 | + if (typeof errorCallback != "function") { |
| 26 | + console.log("PushNotification.unregister failure: failure parameter not a function"); |
| 27 | + return |
| 28 | + } |
14 | 29 |
|
15 |
| - if (typeof successCallback != "function") { |
16 |
| - console.log("PushNotification.register failure: success callback parameter must be a function"); |
17 |
| - return; |
18 |
| - } |
| 30 | + if (typeof successCallback != "function") { |
| 31 | + console.log("PushNotification.unregister failure: success callback parameter must be a function"); |
| 32 | + return |
| 33 | + } |
19 | 34 |
|
20 |
| - cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]); |
21 |
| - }; |
| 35 | + cordova.exec(successCallback, errorCallback, "PushPlugin", "unregister", [options]); |
| 36 | +}; |
22 | 37 |
|
23 |
| - // Call this to unregister for push notifications |
24 |
| - PushNotification.prototype.unregister = function(successCallback, errorCallback) { |
25 |
| - if (errorCallback == null) { errorCallback = function() {}} |
| 38 | +// Call this if you want to show toast notification on WP8 |
| 39 | +PushNotification.prototype.showToastNotification = function (successCallback, errorCallback, options) { |
| 40 | + if (errorCallback == null) { errorCallback = function () { } } |
26 | 41 |
|
27 |
| - if (typeof errorCallback != "function") { |
28 |
| - console.log("PushNotification.unregister failure: failure parameter not a function"); |
29 |
| - return; |
30 |
| - } |
| 42 | + if (typeof errorCallback != "function") { |
| 43 | + console.log("PushNotification.register failure: failure parameter not a function"); |
| 44 | + return |
| 45 | + } |
31 | 46 |
|
32 |
| - if (typeof successCallback != "function") { |
33 |
| - console.log("PushNotification.unregister failure: success callback parameter must be a function"); |
34 |
| - return; |
35 |
| - } |
| 47 | + cordova.exec(successCallback, errorCallback, "PushPlugin", "showToastNotification", [options]); |
| 48 | +} |
36 | 49 |
|
37 |
| - cordova.exec(successCallback, errorCallback, "PushPlugin", "unregister", []); |
38 |
| - }; |
39 |
| - |
40 |
| - |
41 |
| - // Call this to set the application icon badge |
42 |
| - PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallback, badge) { |
43 |
| - if (errorCallback == null) { errorCallback = function() {}} |
| 50 | +// Call this to set the application icon badge |
| 51 | +PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallback, errorCallback, badge) { |
| 52 | + if (errorCallback == null) { errorCallback = function() {}} |
44 | 53 |
|
45 |
| - if (typeof errorCallback != "function") { |
46 |
| - console.log("PushNotification.setApplicationIconBadgeNumber failure: failure parameter not a function"); |
47 |
| - return; |
48 |
| - } |
| 54 | + if (typeof errorCallback != "function") { |
| 55 | + console.log("PushNotification.setApplicationIconBadgeNumber failure: failure parameter not a function"); |
| 56 | + return |
| 57 | + } |
49 | 58 |
|
50 |
| - if (typeof successCallback != "function") { |
51 |
| - console.log("PushNotification.setApplicationIconBadgeNumber failure: success callback parameter must be a function"); |
52 |
| - return; |
53 |
| - } |
| 59 | + if (typeof successCallback != "function") { |
| 60 | + console.log("PushNotification.setApplicationIconBadgeNumber failure: success callback parameter must be a function"); |
| 61 | + return |
| 62 | + } |
54 | 63 |
|
55 |
| - cordova.exec(successCallback, successCallback, "PushPlugin", "setApplicationIconBadgeNumber", [{badge: badge}]); |
56 |
| - }; |
| 64 | + cordova.exec(successCallback, errorCallback, "PushPlugin", "setApplicationIconBadgeNumber", [{badge: badge}]); |
| 65 | +}; |
57 | 66 |
|
58 | 67 | //-------------------------------------------------------------------
|
59 | 68 |
|
60 |
| -if(!window.plugins) { |
61 |
| - window.plugins = {}; |
| 69 | +if (!window.plugins) { |
| 70 | + window.plugins = {}; |
62 | 71 | }
|
63 | 72 | if (!window.plugins.pushNotification) {
|
64 |
| - window.plugins.pushNotification = new PushNotification(); |
| 73 | + window.plugins.pushNotification = new PushNotification(); |
| 74 | +} |
| 75 | + |
| 76 | +if (typeof module != 'undefined' && module.exports) { |
| 77 | + module.exports = PushNotification; |
65 | 78 | }
|
0 commit comments