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] Prevent re-swizzling when there is another swizzler #1100

Merged

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Jun 1, 2022

Description

One Line Summary

Prevent infinite loops between OneSignal and other SDKs that also swizzle.

Details

Motivation

After a recent swizzling change (commit hasn't gotten into a release yet) it was discovered that it introduced a bug with FlutterFire which causes an infinite loop between the two with the AppDelegate. This is due to the fact FlutterFire clears the AppDelegate and re-assigns it and OneSignal re-swizzles it self back. Then when an AppDelegate selector fires from iOS OneSignal and FlutterFire call each other in a loop due to this.

Scope

Effects swizzling for both AppDelegate and UNUserNotificationCenterDelegate.

Testing

Unit testing

Added a unit test that reproduced the exact FlutterFire issue.

Manual testing

Ensured issue no longer happens on the Flutter project with FlutterFire and OneSignal. Tested on an iPhone 6s with iOS 14.4.1 and sent a notification while the app was in the foreground, ensured "onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler: Fired!" was printed to the log.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
    • Swizzling
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

The test added in this commit was based on what FlutterFire does which
was observed to get stuck in an infinite loop. We need to ensure we
swizzle a class only once, we will fix this in the next commit and
explain why.
This was added to prevent an infinite loops when another library that
swizzles the same selectors is present in the app. This was only true
if the other library correctly forwards the event to the original
selector, however this is almost always the case as otherwise this other
SDK would create side effects if it missed the forwarding step.

Basically something can swizzle after OneSignal and swizzle it out of
first inline. However this is ok since that other swizzling library will
just think OneSignal's implementation is the original so therefore
OneSignal will still get the event. We just have trust the other SDK
swizzling is forwarding.
@jkasten2 jkasten2 requested review from nan-li and emawby June 1, 2022 23:53
Ensure we only swizzle an UNUserNotificationCenterDelegate class once.
This was added to prevent an infinite loops when another library that
swizzles the same selectors is present in the app. See the previous
commit where this same logic was added for AppDelegate for more details.
@jkasten2 jkasten2 force-pushed the fix/prevent_reswizzling_when_there_is_another_swizzler branch from 704451a to c568ace Compare June 2, 2022 00:11
Base automatically changed from omit_objc_getClassList_calls_for_swizzling to main June 2, 2022 17:41
@jkasten2 jkasten2 merged commit 68ecf93 into main Jun 2, 2022
@jkasten2 jkasten2 deleted the fix/prevent_reswizzling_when_there_is_another_swizzler branch June 2, 2022 17:43
@emawby emawby mentioned this pull request Jun 16, 2022
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