I hope you are having a great day.
Note: I’m using Ionic 3 for my app.
So I’m stucked with OneSignal’s Push Notifications, last week my Push Notifications stopped working in some devices (I don’t see a pattern, sometimes it does not work in Android, sometimes in iOS).
This is the piece of code in Ionic where I catch the Push Notifications:
this.oneSignal.startInit(AppConstants.ApplicationId, AppConstants.GoogleProjectId);
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);
this.oneSignal.handleNotificationOpened().subscribe(data => {
const type = data.notification.payload.additionalData.type.toUpperCase();
switch (type) {
case 'TYPE_1':
// Do something
break;
case 'TYPE_2':
// Do something else
break;
case 'TYPE_3':
// Do something else
break;
default:
console.log('Notification type not registered');
break;
}
});
this.oneSignal.endInit();
I call that code on the application start.
Every time my users send a Message (it is a feature in the app) I send a request to my REST Service and it sends a request to OneSignal (to their REST API)
The data I post to OneSignal’s REST API is:
{
"app_id": "MY_PRIVATE_APP_ID",
"ios_badgeType": "Increase",
"ios_badgeCount": 1,
"include_player_ids": [
"141b5113-b8a4-4290-b1f7-cca75d3e9760",
"141b6222-b844-3142-b463-ca1359914ff9",
"24349992-c934-2941-c249-ffa514925284",
"43242432-3234-2342-c534-aacb25492590",
],
"priority": 10,
"android_channel_id": "26ca5296-f10f-4294-a3c6-942b1b88141b",
"headings": {
"en": "You have a message",
"es": "Tienes un mensaje"
},
"contents": {
"en": "Rick Sanchez sent you a message",
"es": "Rick Sanches te envió un mensaje"
},
"data": {
"type": "TYPE_1"
}
}
So far, not all recipients received the Push Notification (In that specific example I’m using an iPad with iOS 11, iPhone 7 with iOS 11, Samsung Galaxy S7 with Android 7 and a Motorola G5 with Android 7), I just received in one of them (the iPhone 7), but if I repeat the test then I can get the Push Notification with the Galaxy S7, or even 2, 3 or the 4 devices.
Then if I check the Delivery status in OneSignal dashboard I see that the Push Notification was correctly delivered to all the recipients (so far so good), but not all showed the PN.
Note: my devices are not in a battery saving mode