Fix swizzling subclass of already swizzled class #1284
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Fixing an issue where OneSignal would swizzle a subclass of an already swizzled class
Details
Fixes #1272
Fixes #1143
The bug is only reproducible with both Instabug and Firebase libraries.
The crucial factor here is that Google's libraries create GULApplicationDelegate classes which subclass the App's AppDelegate class.
OneSignal swizzles AppDelegate on load, then the Google libraries set their GULApplicationDelegate classes as the application's delegate, which triggers OneSignal to swizzle again.
This was not creating an issue with only firebase, but when also including Instabug there was an infinite loop. This is because when we swizzle the second time, the original implementation already includes Instabug calling OneSignal's AppDelegate. This means that our new implementation will include calling Instabug, which calls OneSignal, which calls Instabug, etc.
Motivation
Fixes infinite loop issues with other libraries
Scope
AppDelegate swizzling
Testing
Unit testing
New unit test to detect this case
Manual testing
I tested by integrating both Instabug and Firebase. The bug is only reproducible with both of those libraries. I tested on the branch named "instabug_conflict" if reviewers would like to manually test with that integration setup.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is