local-notification.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. for (var key in defaults) {
  30. if (options[key] !== undefined) {
  31. defaults[key] = options[key];
  32. }
  33. }
  34. if (typeof defaults.date == 'object') {
  35. defaults.date = Math.round(defaults.date.getTime()/1000);
  36. }
  37. cordova.exec(null, null, 'LocalNotification','add', [defaults]);
  38. return defaults.id;
  39. },
  40. /**
  41. * Entfernt die angegebene Notification.
  42. *
  43. * @param {String} id
  44. */
  45. cancel: function (id) {
  46. cordova.exec(null, null, 'LocalNotification', 'cancel', [id]);
  47. },
  48. /**
  49. * Entfernt alle registrierten Notifications.
  50. */
  51. cancelAll: function () {
  52. cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
  53. }
  54. };
  55. var plugin = new LocalNotification();
  56. module.exports = plugin;