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

Fix pre-existing notification delegate #926

Merged
merged 8 commits into from
May 18, 2021

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented May 13, 2021

Summary

This fixes an issue where OneSignal's notification open event would not fire if a UNUserNotificationCenterDelegate was assigned before the OneSignal was loaded into memory.

Details

This commit solves it by reassigning the pre-loaded delegate into swizzle in OneSignal's methods.
This issue was discovered through a Unity issue where Unity Mobile Notification Services would load their delegate before OneSignal's delegate.

Tests

  • Added a new test to cover this specific pre-existing case.

Related PR

This applies the same fix from PR #924 but includes some refactoring to make it testable.


This change is Reviewable

* Issue was that the DummyNotificationCenterDelegate was going out of
scope and getting removed.
   - This created an issue where OneSignal swizzling was no longer
   wroking, which broke any notification open tests.
* Moved swizzling logic in setOneSignalUNDelegate into
swizzleSelectorsOnDelegate
   - No logic changes just a move.
* This cleans up code a bit and also makes it more testable.
* Added this method on a new helper to undo swizzling in test
* This way there is zero carry over side-effects on other tests
* Moved this test into it's own testing file.
   - We will be adding more swizzling tests in (a) up comming commit(s)
* Moved registerAsUNNotificationCenterDelegate out of OneSignalHelper
and into OneSignalUNUserNotificationCenter
   - This better encapsulates this logic
* Added a new setup method that OneSignal class.
   - Before OneSignal had to call two methods which as client
   shouldn't have to know or care about it at that level.
* OneSignal is normally loaded into memory and it performs swizzling
before any code is exlcude as it happens in +load.
This is not always the case however so this simulates so other
code winning the setDelegate race.
* Added putIntoPreloadedState helper to simulate OneSignal class
not being loaded into memory yet.
* This happens when another library's delegate is
loaded before OneSignal's delegate code.
* This commit solves it by reassigning the pre loaded
delegate to swizzle in OneSignal's logic
* Updated the comment to better fit what we added in the else
statement from our last commit.
Copy link
Contributor

@emawby emawby left a 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 r1, 2 of 2 files at r2, 3 of 3 files at r3, 2 of 2 files at r4, 6 of 6 files at r5.
Reviewable status: 5 of 9 files reviewed, all discussions resolved (waiting on @emawby and @tanaynigam)

@jkasten2 jkasten2 merged commit cf6a23e into master May 18, 2021
@jkasten2 jkasten2 deleted the fix/pre-existing_notification_delegate_for_master branch May 18, 2021 03:06
@emawby emawby mentioned this pull request May 20, 2021
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

Successfully merging this pull request may close these issues.

2 participants