capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

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

Open fabioz23 opened this issue 3 years ago • 4 comments

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 [email protected], [email protected] to [email protected], [email protected]) 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.

fabioz23 avatar Mar 28 '22 15:03 fabioz23

Hi,

any update?

@jcesarmobile @emawby

fabioz23 avatar Apr 12 '22 07:04 fabioz23

it seems that my ugly workaround doesn't reset the unread notification badge

fabioz23 avatar Apr 15 '22 17:04 fabioz23

@fabioz23 It looks like there is a setting named handleApplicationNotifications that could turn off Capacitor's handling of notifications: https://github.com/ionic-team/capacitor/blob/2b7016f3b4d62fd8c9d03fde2745b3d515bf08b2/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h#L86-L90

However not sure where you would set this to false normally.

jkasten2 avatar May 07 '22 05:05 jkasten2

Same problem here, any update?

daniestrella avatar May 20 '22 06:05 daniestrella

next release of Capacitor (probably 4.4.1) will allow to set handleApplicationNotifications to false so OneSignal and other plugins can have the notification center for themselves. Note that then @capacitor/local-notifications and @capacitor/push-notifications won't work https://github.com/ionic-team/capacitor/pull/6030

jcesarmobile avatar Oct 26 '22 15:10 jcesarmobile

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Nov 25 '22 15:11 ionitron-bot[bot]