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]: UNNotificationServiceExtension didReceiveNotificationExtensionRequest tries to handle UNNotificationRequest that was sent not by OneSignal #1117

Closed
1 task done
alpono opened this issue Aug 17, 2022 · 1 comment

Comments

@alpono
Copy link

alpono commented Aug 17, 2022

What happened?

The problem is with handling push notifications that contain images.

We have UNNotificationServiceExtension implemented and the problem occurs because we have two different push-sending services (Optimove and OneSignal). Both support images, both have their own attachment handler and we have a race condition between them when we receive a push from Optimove.

Both handlers call contentHandler closure and if OneSignal does it faster then the image is skipped due to a different payload structure. Both of the services don’t have any public API that helps the developer to figure out that the push was sent by this specific service and not another so we cannot figure out which handler should be called. Calling Optimove's handler doesn't harm any other service because they try to handle notification requests and call contentHandler closure only if the payload has a specific structure (some list of fields should exist). On the other hand, calling

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

is not safe if you are not sure that notification was sent by OneSignal because OneSignal calls contentHandler closure anyway so if it will be first then push attachment will be skipped at all.

Steps to reproduce?

1. Integrate OneSignal SDK
2. Send a push with an image not from OneSignal dashboard
AR: Image content is skipped
ER: Image is presented in the notification

What did you expect to happen?

I'm expecting to have the ability to figure out was UNNotificationRequest come from OneSignal to avoid calling handler or update the logic of

+(UNMutableNotificationContent *)didReceiveNotificationExtensionRequest:(UNNotificationRequest *)request 
withMutableNotificationContent:(UNMutableNotificationContent *)replacementContent 
withContentHandler:(void (^)(UNNotificationContent *))contentHandler;

to not call contentHandler closure if OneSignal doesn't know how to handle the attachment of received UNNotificationRequest. Not calling contentHandler at all gives that notification is presented anyway but without an image so removing calling contentHandler closure is safe if the notification was sent by any other service.

OneSignal iOS SDK version

3.9.1

iOS version

15, 14, 13, 12, 11 or below

Specific iOS version

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@emawby
Copy link
Contributor

emawby commented Aug 25, 2022

@alpono Thank you for reaching out. I will look into making sure there are no side effects for OneSignal notifications, but in the mean time you can distinguish if it is a OneSignal notification by reading the request.content.userInfo and seeing if it has the os_data field.

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