appfeel / node-pushnotifications

Push notifications for GCM, APNS, MPNS, AMZ (automatic detection from device token)
MIT License
541 stars 127 forks source link

Not receiving push notifications on IOS device. #79

Closed densk1 closed 6 years ago

densk1 commented 6 years ago

I had an issue whereby the Notification was sending through APNS, but that there was no sign of it appearing on my device.

I wanted to reference it here, as it may be valuable to someone in the future.

My issue was that I used the whole example data object from the push example in the docs

3. Create a JSON object with a title and message and send the notification.

What solved it was using the bare minimum in the data object like so.

data: {
    topic: "com.domain.myapp",
    title: 'Message Title',
    body: 'This is the message body',
    badge: 2,
    sound: 'default',
}
alex-friedl commented 6 years ago

Hello @densk1, thank you for your feedback! Do you by any chance know which field(s) in the payload caused the trouble with APNS? Do you have any additional error messages? Then we could potentially adjust the documentation accordingly.

Cheers

densk1 commented 6 years ago

I copy pasted the full object from the docs, so while I'm not sure off hand, I think it was caused by having an empty alert: {} key in my data object.

I'm happy to do a conclusive test this week and submit a PR tweak for docs if it helps.

alex-friedl commented 6 years ago

I would greatly appreciate that! Thank you! :)

densk1 commented 6 years ago

Ok, I've recreated this on IOS 11.3 iPhone 7.

Using the object as is in the docs, adding only a topic value, you get an error that is roughly the following in the device console.

No values for, badge, sound, or alert, not notifying com.example.app

Excuse the roughness, I haven't the test device at home here, just a development build/install on my own device, so can't see device console.

Is that true? No, In the object from docs both badge and sound have values. and alert: { } is an empty object.

What fixed it?

  1. Commenting out the mdm: ' ', // apn and gcm for ios makes the device vibrate but no notification visibly appears.
  2. This is because alert: { } is an empty object if // alert is commented out, notification appears.

Suggestion Is it worth commenting out the mdm line as a default, and adding the following in docs?

alert: { } // apn, will take precedence over title and body. 
// Your notification won't appear on ios if alert is empty object
// If alert is an empty string 'title' and 'body' will show in Notification

// mdm: '' // (Mobile Device Management) apn and gcm for ios
alex-friedl commented 6 years ago

@densk1 Thank you for this research. I will do some more digging because there are ongoing discussions regarding the support of silent push notifications (https://github.com/appfeel/node-pushnotifications/issues/56), which you seem to have got working. I will also look into the mdm parameter and update the docs accordingly once I have some more insight

densk1 commented 6 years ago

Ok great,

Here is a complete list of the device console output when I send the push notification with the un-edited data object.

default 10:05:22.464385 +0100   SpringBoard Received incoming message on topic com.domain.myapp at priority 10
default 10:05:22.465978 +0100   SpringBoard [com.domain.myapp] Received remote notification request B910-1D51 [ hasAlertContent: 0, hasSound: 0 hasBadge: 0 hasContentAvailable: 0 hasMutableContent: 0 ]
default 10:05:22.466121 +0100   SpringBoard [com.domain.myapp] Deliver push notification request B910-1D51
error   10:05:22.466266 +0100   SpringBoard Ignoring notification with no alert, sound or badge (com.domain.myapp): B910-1D51
default 10:05:22.466391 +0100   SpringBoard [com.domain.myapp] Not saving push notification B910-1D51 to store [ error=Error Domain=UNErrorDomain Code=1401 "Notification has no user-facing content" UserInfo={NSLocalizedDescription=Notification has no user-facing content} ]
densk1 commented 6 years ago

I don't think I had silent notifications working, as the device is actually vibrating/beeping, just without a visible notification showing up because alert: {} is empty. (With // mdm: '' commented out) Also .onNotification(); isn't been called.

alex-friedl commented 6 years ago

Hi @densk1 , I added your suggestions for improving the README in e8c684a. Thank you for your input!

sghoe commented 5 years ago

Hello, for our cordova apps we had problems with phonegap: true not receiving pn on ios.

alex-friedl commented 5 years ago

Hello, could you please provide more details? Are there any logs or code you can provide?