OneSignal / OneSignal-Cordova-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Other
249 stars 197 forks source link

[Bug]: None of the events are received #1006

Open j4hangir opened 3 days ago

j4hangir commented 3 days ago

What happened?

Install "onesignal-cordova-plugin": "^5.2.1",

in iOS pod:

target 'OneSignalNotificationServiceExtension' do
  pod 'OneSignalXCFramework', '>= 5.0', '< 6.0'
end

Ionic Vue:

OneSignal.initialize("{app id}")
await OneSignal.Notifications.requestPermission()
OneSignal.login('test')

Everything up until here works fine, notifications are received and displayed when the app is in BG (but not displayed when in FG), however the following never gets logged:

OneSignal.Notifications.addEventListener('click', event => {
            console.log('click event')
        })

NotificationService.swift:

import UserNotifications
import OneSignalExtension

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var receivedRequest: UNNotificationRequest!
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.receivedRequest = request
        self.contentHandler = contentHandler
        self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {
            /* DEBUGGING: Uncomment the 2 lines below to check this extension is executing
                          Note, this extension only runs when mutable-content is set
                          Setting an attachment or action buttons automatically adds this */
            print("Running NotificationServiceExtrension")
            bestAttemptContent.body = "[Modified] " + bestAttemptContent.body

            OneSignalExtension.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
        }
    }

    override func serviceExtensionTimeWillExpire() {
        // Called just before the extension will be terminated by the system.
        // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            OneSignalExtension.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
            contentHandler(bestAttemptContent)
        }
    }
}

Steps to reproduce?

Install basically latest version of as-of now as mentioned above.

What did you expect to happen?

Receive click event.

OneSignal Cordova SDK version

5.2.1

Which platform(s) are affected?

Relevant log output

No response

Code of Conduct

nan-li commented 2 days ago

Hi @j4hangir, What is the app state when the notification is clicked: foreground, background, or killed?

j4hangir commented 2 days ago

Hi @j4hangir, What is the app state when the notification is clicked: foreground, background, or killed?

I tap on the notification, the app is opened and at this point I expect to see some logs (events triggering).