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]: None of the events are received #1006

Open
2 of 3 tasks
j4hangir opened this issue Jun 27, 2024 · 2 comments
Open
2 of 3 tasks

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

j4hangir opened this issue Jun 27, 2024 · 2 comments

Comments

@j4hangir
Copy link

j4hangir commented Jun 27, 2024

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?

  • iOS
  • Android

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@j4hangir j4hangir changed the title [Bug]: [Bug]: None of the events are received Jun 28, 2024
@nan-li
Copy link
Contributor

nan-li commented Jun 28, 2024

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

@j4hangir
Copy link
Author

j4hangir commented Jun 28, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants