[IONIC 4] Actions not working when clicking on OneSignal notification

#1

Hi guys,

I’m creating a chat app with Ionic 4, and I’m using OneSignal to send push notifications to users when a new message is received.
The notification is created on a Symfony backend, everything’s fine, notifications are sent and well received by my users.
Problem is, when I click on a notification, I want to go on my chat between me and the user who sent a message, and see the last message he sent, obviously.
When I click on the notification, my app is running on background.

I have 2 cases, one working and one not:

  1. Working case: When I was using the app and left it, I wasn’t on the Chat page.
  2. Not working case: When I was using the app and left it, I was on the Chat page. In that case, my app opens but I can’t see the last message sent to me (the one in the notification).

I used Events to manage all of this:

app.component.ts:

      this.oneSignal.handleNotificationOpened().subscribe(jsonData => {
        if (jsonData.notification.payload.additionalData.notificationType === 'newChatMessage') {
          this.events.publish('newMessageChat', jsonData.notification.payload.additionalData.content);
          this.router.navigate(['/chat/' + jsonData.notification.payload.additionalData.content.userFrom.id]);
        }
      });

chat.page.ts:

ionViewDidEnter() {
    this.getContactInfos();
    this.getUser();
    this.getMessages();

    this.events.subscribe('newMessageChat', (message) => {
      const msgs = [];
      msgs.push(message);
      this.messages.forEach(msg => {
        msgs.push(msg);
      });
      this.messages = msgs;
      setTimeout(() => {
        this.updateScroll();
      }, 200);
    });
  }

  ionViewWillLeave() {
    this.events.unsubscribe('newMessageChat');
  }

If I console.log('test'); in my event subscription, I see it on my 2 cases. But in case 2., my page isn’t moving, the last message isn’t showing.

Anyone who had this problem before to help me a bit please ?
Thanks guys ! :slight_smile:

#2

Hi @AdamGelineau

Did you solve this navigation problem?
I couldn’t

#3

Hi @kaique09, unfortunately not, I couldn’t yet :confused:

#4

Hi @AdamGelineau

I asked to a person on github and He said this:
“It is not working on iOS. My workaround is to save notifications to DB and check newest notification on my server when the app is initialized and then open url in my app.”

#5

Unfortunately, this is not the same problem as mine