mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-01 02:12:39 +00:00
52 lines
1.2 KiB
Objective-C
52 lines
1.2 KiB
Objective-C
#import "NotificationCenterUtils.h"
|
|
|
|
#import "RuntimeUtils.h"
|
|
|
|
static NSMutableArray *notificationHandlers()
|
|
{
|
|
static NSMutableArray *array = nil;
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^
|
|
{
|
|
array = [[NSMutableArray alloc] init];
|
|
});
|
|
return array;
|
|
}
|
|
|
|
@interface NSNotificationCenter (_a65afc19)
|
|
|
|
@end
|
|
|
|
@implementation NSNotificationCenter (_a65afc19)
|
|
|
|
- (void)_a65afc19_postNotificationName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo
|
|
{
|
|
for (NotificationHandlerBlock handler in notificationHandlers())
|
|
{
|
|
if (handler(aName, anObject, aUserInfo))
|
|
return;
|
|
}
|
|
|
|
[self _a65afc19_postNotificationName:aName object:anObject userInfo:aUserInfo];
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation NotificationCenterUtils
|
|
|
|
+ (void)load
|
|
{
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^
|
|
{
|
|
[RuntimeUtils swizzleInstanceMethodOfClass:[NSNotificationCenter class] currentSelector:@selector(postNotificationName:object:userInfo:) newSelector:@selector(_a65afc19_postNotificationName:object:userInfo:)];
|
|
});
|
|
}
|
|
|
|
+ (void)addNotificationHandler:(bool (^)(NSString *, id, NSDictionary *))handler
|
|
{
|
|
[notificationHandlers() addObject:[handler copy]];
|
|
}
|
|
|
|
@end
|