local-notification.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. */
  17. add: function (options) {
  18. var defaults = {
  19. date: false,
  20. message: '',
  21. title: '',
  22. badge: 0,
  23. id: 0,
  24. sound: '', // nur iOS
  25. background: '',
  26. foreground: ''
  27. };
  28. for (var key in defaults) {
  29. if (options[key] !== undefined) {
  30. defaults[key] = options[key];
  31. }
  32. }
  33. if (typeof defaults.date == 'object') {
  34. defaults.date = Math.round(defaults.date.getTime()/1000);
  35. }
  36. cordova.exec(null, null, 'LocalNotification','add', [defaults]);
  37. },
  38. /**
  39. * Entfernt die angegebene Notification.
  40. *
  41. * @param {String} id
  42. */
  43. cancel: function (id) {
  44. cordova.exec(null, null, 'LocalNotification', 'cancel', [id]);
  45. },
  46. /**
  47. * Entfernt alle registrierten Notifications.
  48. */
  49. cancelAll: function () {
  50. cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
  51. }
  52. };
  53. var plugin = new LocalNotification();
  54. module.exports = plugin;