apsProperties.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. module.exports = {
  2. set alert(value) {
  3. this.aps.alert = value;
  4. },
  5. get body() {
  6. if (this.aps.alert) {
  7. return this.aps.alert.body || this.aps.alert;
  8. }
  9. return this.aps.alert;
  10. },
  11. set body(value) {
  12. if (typeof this.aps.alert !== 'object') {
  13. this.aps.alert = value;
  14. } else {
  15. this.prepareAlert();
  16. this.aps.alert.body = value;
  17. }
  18. },
  19. set locKey(value) {
  20. this.prepareAlert();
  21. this.aps.alert['loc-key'] = value;
  22. },
  23. set locArgs(value) {
  24. this.prepareAlert();
  25. this.aps.alert['loc-args'] = value;
  26. },
  27. set title(value) {
  28. this.prepareAlert();
  29. this.aps.alert.title = value;
  30. },
  31. set subtitle(value) {
  32. this.prepareAlert();
  33. this.aps.alert.subtitle = value;
  34. },
  35. set titleLocKey(value) {
  36. this.prepareAlert();
  37. this.aps.alert['title-loc-key'] = value;
  38. },
  39. set titleLocArgs(value) {
  40. this.prepareAlert();
  41. this.aps.alert['title-loc-args'] = value;
  42. },
  43. set action(value) {
  44. this.prepareAlert();
  45. this.aps.alert.action = value;
  46. },
  47. set actionLocKey(value) {
  48. this.prepareAlert();
  49. this.aps.alert['action-loc-key'] = value;
  50. },
  51. set launchImage(value) {
  52. this.prepareAlert();
  53. this.aps.alert['launch-image'] = value;
  54. },
  55. set badge(value) {
  56. if (typeof value === 'number' || value === undefined) {
  57. this.aps.badge = value;
  58. }
  59. },
  60. set sound(value) {
  61. if (typeof value === 'string' || value === undefined) {
  62. this.aps.sound = value;
  63. } else if (
  64. typeof value === 'object' &&
  65. typeof value.name === 'string' &&
  66. typeof value.critical === 'number' &&
  67. typeof value.volume === 'number'
  68. ) {
  69. this.aps.sound = value;
  70. }
  71. },
  72. set relevanceScore(value) {
  73. if (typeof value === 'number' || value === undefined) {
  74. this.aps['relevance-score'] = value;
  75. }
  76. },
  77. set timestamp(value) {
  78. if (typeof value === 'number' || value === undefined) {
  79. this.aps.timestamp = value;
  80. }
  81. },
  82. set staleDate(value) {
  83. if (typeof value === 'number' || value === undefined) {
  84. this.aps['stale-date'] = value;
  85. }
  86. },
  87. set events(value) {
  88. if (typeof value === 'string' || value === undefined) {
  89. this.aps.events = value;
  90. }
  91. },
  92. set contentState(value) {
  93. if (typeof value === 'object' || value === undefined) {
  94. this.aps['content-state'] = value;
  95. }
  96. },
  97. set contentAvailable(value) {
  98. if (value === true || value === 1) {
  99. this.aps['content-available'] = 1;
  100. } else {
  101. this.aps['content-available'] = undefined;
  102. }
  103. },
  104. set mutableContent(value) {
  105. if (value === true || value === 1) {
  106. this.aps['mutable-content'] = 1;
  107. } else {
  108. this.aps['mutable-content'] = undefined;
  109. }
  110. },
  111. set mdm(value) {
  112. this._mdm = value;
  113. },
  114. set urlArgs(value) {
  115. if (Array.isArray(value) || value === undefined) {
  116. this.aps['url-args'] = value;
  117. }
  118. },
  119. set category(value) {
  120. if (typeof value === 'string' || value === undefined) {
  121. this.aps.category = value;
  122. }
  123. },
  124. set targetContentIdentifier(value) {
  125. if (typeof value === 'string' || value === undefined) {
  126. this.aps['target-content-id'] = value;
  127. }
  128. },
  129. set threadId(value) {
  130. if (typeof value === 'string' || value === undefined) {
  131. this.aps['thread-id'] = value;
  132. }
  133. },
  134. set interruptionLevel(value) {
  135. if (typeof value === 'string' || value === undefined) {
  136. this.aps['interruption-level'] = value;
  137. }
  138. },
  139. prepareAlert: function () {
  140. if (typeof this.aps.alert !== 'object') {
  141. this.aps.alert = { body: this.aps.alert };
  142. }
  143. },
  144. };