moldstadt
moldstadt

Reputation: 362

Receive OneSignal background notification in Ionic 2 app

I am using OneSignal push notifications in my Ionic 2 app. It works fine except for the following case:

I have called OneSignal.handleNotificationReceived().subscribe(), during initialisation, but this is not triggered unless the app is running in the foreground/background.

Is there any way to get the notification when the app is started, even if the user dismissed the notification.

Thanks.

Upvotes: 3

Views: 1120

Answers (1)

Mr.P
Mr.P

Reputation: 1430

There is no way to achieve what you're trying to achieve through the use of OneSignal alone. The OneSignal plugin for Ionic 2 has two calls to action:

handleNotificationReceived() & handleNotificationOpened()

The first one is called when the notification is received and the app is in the foreground, and the second is called when the app is launched from the notification.

You'd need some other service to record when notifications are sent to see if there were any when the app was launched by itself. If you use OneSignal's REST API to send notifications yourself, you can record when a notification is sent, and then when the app is launched by itself, and not from the notification, you can fetch missed notifications or notification count from your own server. That's just one way you can do it.

But ultimately OneSignal is a push notification service, and that's all it does, send notifications. Even if you did APNS or FCM yourself and went through the scenario you outlined, the results would be the same, it's not a OneSignal issue. It's the way notifications are designed.

Upvotes: 1

Related Questions