39 lines
1.4 KiB
Objective-C
39 lines
1.4 KiB
Objective-C
#import <Foundation/Foundation.h>
|
|
#import <UIKit/UIKit.h>
|
|
#import <objc/message.h>
|
|
#import <objc/runtime.h>
|
|
|
|
@implementation UIStatusBarManager (CAPHandleTapAction)
|
|
|
|
+ (void)load {
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^{
|
|
Class class = [self class];
|
|
SEL originalSelector = NSSelectorFromString(@"handleTapAction:");
|
|
SEL swizzledSelector = @selector(custom_handleTapAction:);
|
|
|
|
Method originalMethod = class_getInstanceMethod(self, originalSelector);
|
|
Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector);
|
|
|
|
BOOL didAddMethod = class_addMethod(class,
|
|
originalSelector,
|
|
method_getImplementation(swizzledMethod),
|
|
method_getTypeEncoding(swizzledMethod));
|
|
if (didAddMethod) {
|
|
class_replaceMethod(class,
|
|
swizzledSelector,
|
|
method_getImplementation(originalMethod),
|
|
method_getTypeEncoding(originalMethod));
|
|
} else {
|
|
method_exchangeImplementations(originalMethod, swizzledMethod);
|
|
}
|
|
});
|
|
}
|
|
|
|
-(void)custom_handleTapAction:(id)sender {
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"org.joinmastodon.app.statusBarTapped" object:sender];
|
|
[self custom_handleTapAction:sender];
|
|
}
|
|
|
|
@end
|