braze-swift-sdk icon indicating copy to clipboard operation
braze-swift-sdk copied to clipboard

[Feature]: Enable filtering push notifications

Open PlanesWalkerr opened this issue 2 years ago • 1 comments

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

PlanesWalkerr avatar Nov 24 '23 13:11 PlanesWalkerr

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!

jerielng avatar Jan 17 '24 19:01 jerielng

Hi @PlanesWalkerr,

We're closing this ticket due to inactivity, feel free to re-open it if you're still facing this issue.

Best,

lowip avatar Jul 03 '24 13:07 lowip