Skip to content

Commit 49c31b4

Browse files
authored
Merge pull request #25 from onmyway133/apns_push_type
Add support for `apns-push-type` which is required for delivering iOS 13 notifications
2 parents f3bdc03 + 7c9cf79 commit 49c31b4

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

components/InputComponent.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,27 @@ class InputComponent extends React.Component {
147147
notification.collapseId = collapseId
148148
}
149149

150+
// New iOS 13+ mandatory header, `apns-push-type`. Can be either `alert` or `background`.
151+
// The value of this header must accurately reflect the contents of the notification's payload.
152+
// More here: https://github.com/node-apn/node-apn/pull/656/commits/cd44a3e2604eebdd5db04235daf035cf353f544a
153+
notification.pushType = "alert"
154+
150155
try {
151-
notification.rawPayload = JSON.parse(input.message)
156+
const json = JSON.parse(input.message)
157+
notification.rawPayload = json
158+
159+
// If `content-available` equals 1 and `aps` dictionary doesn't contain any other keys, the notification is silent.
160+
// `apns-push-type` must be set to `background` for iOS 13+.
161+
const aps = json["aps"]
162+
if (aps && aps["content-available"] === 1) {
163+
let size = 0, key
164+
for (key in aps) {
165+
size++
166+
}
167+
if (size === 1) {
168+
notification.pushType = "background"
169+
}
170+
}
152171
} catch(e) {
153172
this.props.updateOutput({
154173
loading: false,
@@ -162,6 +181,11 @@ class InputComponent extends React.Component {
162181
// provider
163182
const provider = new APN.Provider(options)
164183

184+
this.props.updateOutput({
185+
loading: true,
186+
text: "Sending ".concat(notification.pushType, " notification")
187+
})
188+
165189
provider.send(notification, input.deviceToken).then( (result) => {
166190
if (result.failed.length > 0) {
167191
this.props.updateOutput({

package-lock.json

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030
},
3131
"dependencies": {
32-
"apn": "^2.2.0",
32+
"apn": "node-apn/node-apn#master",
3333
"electron-store": "^2.0.0",
3434
"fs-extra": "^8.1.0",
3535
"material-ui": "0.20.1",

0 commit comments

Comments
 (0)