local-notification.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * locale-notification.js
  3. * Cordova LocalNotification Plugin
  4. *
  5. * Created by Sebastian Katzer (github.com/katzer) on 10/08/2013.
  6. * Copyright 2013 Sebastian Katzer. All rights reserved.
  7. * GPL v2 licensed
  8. */
  9. var LocalNotification = function () {
  10. };
  11. LocalNotification.prototype = {
  12. /**
  13. * Fügt einen neuen Eintrag zur Registry hinzu.
  14. *
  15. * @param {Object} options
  16. * @return {Number} Die ID der Notification
  17. */
  18. add: function (options) {
  19. var defaults = {
  20. date: false,
  21. message: '',
  22. title: '',
  23. badge: 0,
  24. id: 0,
  25. sound: '', // nur iOS
  26. background: '',
  27. foreground: ''
  28. };
  29. var callbackFn = function (cmd) {
  30. eval(cmd);
  31. };
  32. for (var key in defaults) {
  33. if (options[key] !== undefined) {
  34. defaults[key] = options[key];
  35. }
  36. }
  37. if (typeof defaults.date == 'object') {
  38. defaults.date = Math.round(defaults.date.getTime()/1000);
  39. }
  40. cordova.exec(callbackFn, null, 'LocalNotification', 'add', [defaults]);
  41. return defaults.id;
  42. },
  43. /**
  44. * Entfernt die angegebene Notification.
  45. *
  46. * @param {String} id
  47. */
  48. cancel: function (id) {
  49. cordova.exec(null, null, 'LocalNotification', 'cancel', [id]);
  50. },
  51. /**
  52. * Entfernt alle registrierten Notifications.
  53. */
  54. cancelAll: function () {
  55. cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
  56. }
  57. };
  58. var plugin = new LocalNotification();
  59. module.exports = plugin;