-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcordova.LocalNotification.js
61 lines (50 loc) · 1.68 KB
/
cordova.LocalNotification.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
/*!
* Cordova 2.3.0+ LocalNotification plugin
* Original author: Olivier Lesnicki
*/
window.addNotification = function(options) {
var defaults = {
fireDate : new Date(new Date().getTime() + 5000),
alertBody : "This is a local notification.",
repeatInterval : "" ,
soundName : "beep.caf" ,
badge : 0 ,
notificationId : 1 ,
callBack : function(notificationId){}
};
if(options){
for (var key in defaults) {
if (typeof options[key] !== "undefined"){
defaults[key] = options[key];
}
}
}
if (typeof defaults.fireDate == 'object') {
defaults.fireDate = Math.round(defaults.fireDate.getTime()/1000);
}
cordova.exec(
function(notificationId) {
window.setTimeout(function(){
if(typeof defaults.callBack == 'function'){
defaults.callBack(notificationId);
}
}, 1);
},
null,
"LocalNotification" ,
"addNotification" ,
[
defaults.fireDate ,
defaults.alertBody ,
defaults.repeatInterval ,
defaults.soundName ,
defaults.notificationId
]
);
};
window.cancelNotification = function(str, callback) {
cordova.exec(callback, null, "LocalNotification", "cancelNotification", [str]);
};
window.cancelAllNotifications = function(callback) {
cordova.exec(callback, null, "LocalNotification", "cancelAllNotifications", []);
};