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

[Feature]: Enable filtering push notifications #94

Open
PlanesWalkerr opened this issue Nov 24, 2023 · 1 comment
Open

[Feature]: Enable filtering push notifications #94

PlanesWalkerr opened this issue Nov 24, 2023 · 1 comment

Comments

@PlanesWalkerr
Copy link

What problem are you facing?

I want to filter some push notifications according to Apple documentation.
Subclassing from BrazeNotificationService.NotificationService in NotificationServiceExtension doesn't allow me to override UNNotificationServiceExtension.didReceive(_:withContentHandler:) method. Is there any way to filter push notifications?

Workarounds

Seems like it's not possible in current version.

Ideal Solution

Maybe add optional handler where an app can decide if push notification should be shown

Other Information

No response

@jerielng
Copy link
Collaborator

jerielng commented Jan 17, 2024

Hey @PlanesWalkerr, it sounds like you're trying to add your own custom logic in UNNotificationServiceExtension.didReceive(_:withContentHandler:), is that correct?

The Braze implementation of that method calls the brazeHandle method, which is publicly available. What you could do instead of directly inheriting from BrazeNotificationService.NotificationService is to simply implement UNNotificationServiceExtension yourself, and when you override didReceive(_:withContentHandler:), you can call the brazeHandle method, along with your own custom logic.

The minimal implementation on that page should describe how the method would look like, but in summary, it would be something like this:

class YourNotificationService: UNNotificationServiceExtension {
  override func didReceive(
  _ request: UNNotificationRequest,
  withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
) {
  if brazeHandle(request: request, contentHandler: contentHandler) {
    return
  }

  // Your custom logic

  contentHandler(request.content)
 }
}

Let us know if that implementation works for your use case, and if so, feel free to close this issue! Thank you!

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

No branches or pull requests

2 participants