diff --git a/doc/notification.markdown b/doc/notification.markdown index a94b228a..7a1f9682 100644 --- a/doc/notification.markdown +++ b/doc/notification.markdown @@ -105,6 +105,7 @@ This table shows the name of the setter, with the key-path of the underlying pro | `urlArgs` | `aps.url-args` | `Array` | | `category` | `aps.category` | `String` | | `threadId` | `aps.thread-id` | `String` | +| `interruptionLevel` | `aps.interruption-level` | `String` | | `mdm` | `mdm` | `String` | When the notification is transmitted these properties will be added to the output before encoding. diff --git a/lib/notification/apsProperties.js b/lib/notification/apsProperties.js index 7d67b6e9..2c7f0678 100644 --- a/lib/notification/apsProperties.js +++ b/lib/notification/apsProperties.js @@ -122,6 +122,12 @@ module.exports = { } }, + set interruptionLevel(value) { + if(typeof value === "string" || value === undefined) { + this.aps["interruption-level"] = value; + } + }, + prepareAlert: function () { if (typeof this.aps.alert !== "object") { this.aps.alert = {"body": this.aps.alert}; diff --git a/lib/notification/index.js b/lib/notification/index.js index 8abd0b41..a4957597 100644 --- a/lib/notification/index.js +++ b/lib/notification/index.js @@ -27,7 +27,7 @@ Notification.prototype = require("./apsProperties"); ["payload", "expiry", "priority", "alert", "body", "locKey", "locArgs", "title", "subtitle", "titleLocKey", "titleLocArgs", "action", "actionLocKey", "launchImage", "badge", "sound", "contentAvailable", -"mutableContent", "mdm", "urlArgs", "category", "threadId"].forEach( propName => { +"mutableContent", "mdm", "urlArgs", "category", "threadId", "interruptionLevel"].forEach( propName => { const methodName = "set" + propName[0].toUpperCase() + propName.slice(1); Notification.prototype[methodName] = function (value) { this[propName] = value; diff --git a/test/notification/apsProperties.js b/test/notification/apsProperties.js index 7ab4fbfc..5615a21d 100644 --- a/test/notification/apsProperties.js +++ b/test/notification/apsProperties.js @@ -711,6 +711,32 @@ describe("Notification", function() { }); }); + describe("interruption-level", function() { + it("defaults to undefined", function() { + expect(compiledOutput()).to.not.have.nested.property("aps.interruption\-level"); + }); + + it("can be set to a string", function() { + note.interruptionLevel = "the-interruption-level"; + + expect(compiledOutput()).to.have.nested.property("aps.interruption\-level", "the-interruption-level"); + }); + + it("can be set to undefined", function() { + note.interruptionLevel = "the-interruption-level"; + note.interruptionLevel = undefined; + + expect(compiledOutput()).to.not.have.nested.property("aps.interruption\-level"); + }); + + describe("setInterruptionLevel", function () { + it("is chainable", function () { + expect(note.setInterruptionLevel("the-interruption-level")).to.equal(note); + expect(compiledOutput()).to.have.nested.property("aps.interruption\-level", "the-interruption-level"); + }); + }); + }); + context("when no aps properties are set", function() { it("is not present", function() { expect(compiledOutput().aps).to.be.undefined;