Skip to content

Commit 0acb014

Browse files
Nightsd01jkasten2
authored andcommitted
Fix Swizzling Test
• This is a *temporary* solution to a bug we've had with an old test. • The `testSwizzling` test causes the `UNUserNotificationCenterDelegate` to get nullified on the notification center singleton. • Since some tests use this delegate to mock a push notification delivery, this can break these tests • Since XCTest cases are run in alphabetical order, we've been lucky that we've never noticed this in the past since `testSwizzling` was run AFTER all of our tests that use the `UNUserNotificationCenterDelegate.willPresentNotification...` method are alphabetically BEFORE the testSwizzling test • TODO: The notification center delegate gets set to a dummy instance then nullified. We COULD fix this by simply resetting it back to the original value - but this causes issues with swizzling • We will probably need to change the `setOneSignalUNDelegate` swizzle method to make sure it allows the UNUserNotificationCenterDelegate to be reset without messing up the swizzling which causes infinite loops, etc.
1 parent c40cf0f commit 0acb014

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,10 @@ - (void)testPushNotificationToken {
19181918
}
19191919

19201920
//tests to make sure that UNNotificationCenter setDelegate: duplicate calls don't double-swizzle for the same object
1921-
- (void)testSwizzling {
1921+
// TODO: This test causes the UNUserNotificationCenter singleton's Delegate property to get nullified
1922+
// Unfortunately the fix is not as simple as just setting it back to the original when the test is done
1923+
// To avoid breaking other tests, this test should be executed last, and since tests are alphabetical order, adding Z's does this.
1924+
- (void)testZSwizzling {
19221925
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
19231926

19241927
DummyNotificationCenterDelegate *delegate = [[DummyNotificationCenterDelegate alloc] init];

0 commit comments

Comments
 (0)