bug: Onesignal notification not shown on iOS with the app in foreground
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
- Create a simple project using cordova-onesignal-plugin
- make all necessary configs on Onesignal side.
- 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.
Hi,
any update?
@jcesarmobile @emawby
it seems that my ugly workaround doesn't reset the unread notification badge
@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.
Same problem here, any update?
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
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.