-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swizzle UNUserNotificationCenterDelegate once
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.
- Loading branch information
Showing
6 changed files
with
135 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
iOS_SDK/OneSignalSDK/UnitTests/Shadows/OneSignalUNUserNotificationCenterOverrider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface OneSignalUNUserNotificationCenterOverrider : NSObject | ||
+ (int)callCountForSelector:(NSString*)selector; | ||
+ (void)reset; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
32 changes: 32 additions & 0 deletions
32
iOS_SDK/OneSignalSDK/UnitTests/Shadows/OneSignalUNUserNotificationCenterOverrider.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#import "OneSignalUNUserNotificationCenterOverrider.h" | ||
|
||
#import "TestHelperFunctions.h" | ||
#import "UNUserNotificationCenter+OneSignal.h" | ||
|
||
@implementation OneSignalUNUserNotificationCenterOverrider | ||
static NSMutableDictionary* callCount; | ||
|
||
+ (void)load { | ||
callCount = [NSMutableDictionary new]; | ||
|
||
injectStaticSelector( | ||
[OneSignalUNUserNotificationCenterOverrider class], | ||
@selector(overrideTraceCall:), | ||
[OneSignalUNUserNotificationCenter class], | ||
@selector(traceCall:) | ||
); | ||
} | ||
|
||
+ (void)reset { | ||
callCount = [NSMutableDictionary new]; | ||
} | ||
|
||
+ (void)overrideTraceCall:(NSString*)selector { | ||
NSNumber *value = callCount[selector]; | ||
callCount[selector] = [NSNumber numberWithInt:[value intValue] + 1]; | ||
} | ||
|
||
+ (int)callCountForSelector:(NSString*)selector { | ||
return [callCount[selector] intValue]; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters