Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fabioz23 opened this issue Mar 28, 2022 · 6 comments
Closed

Comments

@fabioz23
Copy link

fabioz23 commented Mar 28, 2022

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

This comment was marked as abuse.

@fabioz23
Copy link
Author

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

@jkasten2
Copy link

jkasten2 commented May 7, 2022

@fabioz23 It looks like there is a setting named handleApplicationNotifications that could turn off Capacitor's handling of notifications:

/**
@brief Whether or not the Capacitor runtime will set itself as the @c UNUserNotificationCenter delegate.
@discussion Defaults to @c true. Required to be @c true for notification plugins to work correctly. Set to @c false if your application will handle notifications independently.
*/
@property (nonatomic, assign) BOOL handleApplicationNotifications;

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

@daniestrella
Copy link

Same problem here, any update?

@jcesarmobile
Copy link
Member

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
#6030

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 25, 2022

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 ionitron-bot bot locked and limited conversation to collaborators Nov 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants