-
Notifications
You must be signed in to change notification settings - Fork 267
Fix forwarding notification opens from non onesignal notifs #1131
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
Conversation
2789b26
to
d13759a
Compare
didReceiveNotificationResponse:(UNNotificationResponse *)response | ||
OneSignalCenter:(id)instance | ||
withCompletionHandler:(void(^)())completionHandler { | ||
// Call orginal selector if one was set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: original
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
|
||
[OneSignalUNUserNotificationCenter processiOS10Open:response]; | ||
|
||
[OneSignalUNUserNotificationCenter forwardReceivedNotificationResponseWithCenter:center didReceiveNotificationResponse:response OneSignalCenter:self withCompletionHandler:completionHandler]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emawby Only curious, we want to forward it in any case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct anything that we Swizzle we need to forward regardless of contents/origin. There could be other SDKs that are listening to the method or the app developer could be listening to it as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even notifications that test true to
![OneSignalHelper isOneSignalPayload:response.notification.request.content.userInfo]
?
So the if statement checks if the following should be run
[OneSignalUNUserNotificationCenter processiOS10Open:response];
Maybe invert the if statement and put [OneSignalUNUserNotificationCenter processiOS10Open:response];
inside it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call. I inverted the check
d13759a
to
9555994
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @emawby, @fhboswell, @jennantilla, and @nan-li)
iOS_SDK/OneSignalSDK/UnitTests/UIApplicationDelegateSwizzlingTests.m
line 516 at r2 (raw file):
} - (void)testNotificationOpenForwardsToLegacySelector {
Thinking we should also create a test for a non-OneSignal notification as well, to confirm the fix worked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @fhboswell, @jennantilla, @jkasten2, and @nan-li)
iOS_SDK/OneSignalSDK/UnitTests/UIApplicationDelegateSwizzlingTests.m
line 516 at r2 (raw file):
Previously, jkasten2 (Josh Kasten) wrote…
Thinking we should also create a test for a non-OneSignal notification as well, to confirm the fix worked.
The first notification in the test is a Onesignal notification the second one is a non Onesignal notification
We previously were only forwarding to the legacy selector for OneSignal notifications. Now the forwarding behavior will be the same regardless of notif contents/origin.
9555994
to
5bfb129
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @emawby, @fhboswell, @jennantilla, and @nan-li)
iOS_SDK/OneSignalSDK/UnitTests/UIApplicationDelegateSwizzlingTests.m
line 516 at r2 (raw file):
Previously, emawby (Elliot Mawby) wrote…
The first notification in the test is a Onesignal notification the second one is a non Onesignal notification
ah my bad, looked it too quick! It would be easier to read if this was two different tests, but that improvement that optional for this PR.
Description
One Line Summary
Fixing a swizzling issue where for non OneSignal notifications we were not forwarding notification opens to the app delegate remoteNotificationReceive.
Details
We were doing this properly for OneSignal notifs but not properly for non OneSignal notifications. Now the behavior will be the same regardless of notification content/source.
When a notification is opened our swizzled implementation of UserNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: is called. We need to forward this call to other implementations of this method (which we were doing correctly). However if there are no other implementers of the UNUserNotificationCenter method then we also need to try forwarding to the old app delegate selector in case there are listeners to the legacy method but not the new one.
Motivation
swizzling bug
Scope
notification opens
Testing
Unit testing
Added a unit test that tests forwarding opens to the app delegate selector for both OneSignal and non OneSignal payloads.
Manual testing
tested against firebase messaging on a physical iOS device
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is