Skip to content

Feat: Add option to disable swizzling#1650

Merged
nan-li merged 5 commits intomainfrom
feat/disable_swizzling_option
Mar 10, 2026
Merged

Feat: Add option to disable swizzling#1650
nan-li merged 5 commits intomainfrom
feat/disable_swizzling_option

Conversation

@nan-li
Copy link
Contributor

@nan-li nan-li commented Mar 2, 2026

Description

One Line Summary

Add option to disable swizzling and add manual integration APIs, when disabled.

Details

Motivation

Allow disabling swizzling for developers to have more control over notification delegate methods.

New Manual Integration APIs

If swizzling is enabled but the new forwarding APIs are used, those APIs would no-op and log a warning.

All new manual integration APIs are called on the OneSignal.Notifications namespace:

Objective-C Swift (NS_SWIFT_NAME) Purpose
didRegisterForRemoteNotificationsWithDeviceToken: didRegisterForRemoteNotifications(deviceToken:) Forward APNs token
didFailToRegisterForRemoteNotificationsWithError: didFailToRegisterForRemoteNotifications(error:) Forward registration failure
didReceiveRemoteNotification:completionHandler: didReceiveRemoteNotification(userInfo:completionHandler:) Forward background/silent notification
willPresentNotificationWithPayload:completion: willPresentNotification(payload:completion:) Forward foreground notification
didReceiveNotificationResponse: didReceiveNotificationResponse(_:) Forward tap/action
setBadgeCount: setBadgeCount(_:) Set badge count

How to test

Commit dev app: setup to test swizzle disabled is setup to allow testing

Scope

Swizzling disable option

Testing

Unit testing

None

Manual testing

iPhone on iOS 26.3 with sizzling disabled via Info.plist for:

  • init, APNS token, notification displays, listeners, click handling, permissions, badge count, NSE, etc

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • 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

@nan-li nan-li force-pushed the feat/disable_swizzling_option branch from 3e44488 to e356949 Compare March 5, 2026 20:33
nan-li added 2 commits March 5, 2026 13:40
- Added APIs for manual notification handling and lifecycle observation when swizzling is disabled.
- Introduced a new constant for controlling swizzling via Info.plist.
@nan-li nan-li force-pushed the feat/disable_swizzling_option branch from e356949 to 81fbfe7 Compare March 5, 2026 21:40
+ (BOOL)isSwizzlingDisabled {
static BOOL _cached = NO;
static BOOL _disabled = NO;
if (!_cached) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this protected from multiple threads accessing this method?

Copy link
Contributor Author

@nan-li nan-li Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will address, but two threads could both see _cached == NO and both compute the value. In practice it's harmless since the plist value is immutable and both threads would write the same result, but it's not good practice

@nan-li nan-li requested a review from abdulraqeeb33 March 6, 2026 20:51
+ (BOOL)isSwizzlingDisabled {
static BOOL _disabled = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

nan-li added 2 commits March 9, 2026 23:52
* thread safety
* rename a method for clarity
minimum is ios 12
@nan-li nan-li force-pushed the feat/disable_swizzling_option branch from 36118ce to f5b9997 Compare March 10, 2026 06:52
@nan-li nan-li merged commit 4c43395 into main Mar 10, 2026
4 checks passed
@nan-li nan-li deleted the feat/disable_swizzling_option branch March 10, 2026 15:44
@github-actions github-actions bot mentioned this pull request Mar 10, 2026
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