question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Onesignal notification not shown on iOS with the app in foreground

See original GitHub issue

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 3.4.3
  @capacitor/core: 3.4.3
  @capacitor/android: 3.4.3
  @capacitor/ios: 3.4.3

Installed Dependencies:

  @capacitor/cli: 3.4.3
  @capacitor/android: 3.4.3
  @capacitor/core: 3.4.3
  @capacitor/ios: 3.4.3

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

iOS

Current Behavior

After project upgrade (from Capacitor@2.5.0, onesignal-cordova-plugin@2.11.4 to Capacitor@3.4.3, onesignal-cordova-plugin@3.0.2) Onesignal push notification not shown when the app is in foreground. This happens despite having configured the proper handler for foreground notifications like Onesignal wiki suggest.

Expected Behavior

Inbound Push Notification shown by OS

Code Reproduction

  1. Create a simple project using cordova-onesignal-plugin
  2. make all necessary configs on Onesignal side.
  3. Send a test notification from Onesignal dashboard.

Other Technical Details

npm --version output: 8.5.5

node --version output: v14.17.0

pod --version output (iOS issues only): 1.11.3

Additional Context

My workaround is to forcibly disable handleApplicationNotifications member of NotificationRouter class:

import Foundation

@objc(CAPNotificationRouter) public class NotificationRouter: NSObject, UNUserNotificationCenterDelegate {
    /*var handleApplicationNotifications: Bool {
        get {
            return UNUserNotificationCenter.current().delegate === self
        }
        set {
            let center = UNUserNotificationCenter.current()

            if newValue {
                center.delegate = self
            } else if center.delegate === self {
                center.delegate = nil
            }
        }
    }*/
    var handleApplicationNotifications: Bool = false

...
...

After doing this i was capable to receive push notification on iOS and the app in foreground.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
daniapp2ucommented, May 20, 2022

Same problem here, any update?

3reactions
fabioz23commented, Sep 6, 2022

Hi,

any update?

@jcesarmobile @emawby

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notifications Not Shown - Mobile Push
Common reasons why Mobile Push notifications are not showing on your device. ... "Delivered" notifications in OneSignal means we have successfully sent the ......
Read more >
iOS - Notification not shown on with the app in foreground ...
This happens despite having configured the proper handler for foreground notifications like Onesignal wiki suggest. ... Steps to Reproduce Issue:.
Read more >
OneSignal does not showing notification when app is in ...
Here you go: OneSignal.shared .setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event) { print('FOREGROUND HANDLER ...
Read more >
awesome_notifications | Flutter Package
A complete solution to create Local and Push Notifications, customizing buttons, images, sounds, emoticons and applying many different layouts for Flutter ...
Read more >
How to perform action when user tap on push notification ...
It has since been replaced with the UNUserNotificationCenter class after iOS 10. To handle push notification in App Delegate, we will set the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found