From 7cb77c87333fb88a2b9d4eefb784d84fe2083c9c Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Tue, 3 Mar 2020 14:54:55 +0100 Subject: [PATCH] fix(ios): implement statusTap for iOS 13 (#2376) --- ios/Capacitor/Capacitor/CAPBridge.swift | 2 +- .../UIStatusBarManager+CAPHandleTapAction.m | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 ios/Capacitor/Capacitor/UIStatusBarManager+CAPHandleTapAction.m diff --git a/ios/Capacitor/Capacitor/CAPBridge.swift b/ios/Capacitor/Capacitor/CAPBridge.swift index bc4a60dfa3..e621bd9bac 100644 --- a/ios/Capacitor/Capacitor/CAPBridge.swift +++ b/ios/Capacitor/Capacitor/CAPBridge.swift @@ -9,7 +9,7 @@ enum BridgeError: Error { @objc public class CAPBridge : NSObject { - public static let statusBarTappedNotification = Notification(name: Notification.Name(rawValue: "statusBarTappedNotification")) + @objc public static let statusBarTappedNotification = Notification(name: Notification.Name(rawValue: "statusBarTappedNotification")) public static var CAP_SITE = "https://capacitor.ionicframework.com/" public static var CAP_FILE_START = "/_capacitor_file_" public static let CAP_DEFAULT_SCHEME = "capacitor" diff --git a/ios/Capacitor/Capacitor/UIStatusBarManager+CAPHandleTapAction.m b/ios/Capacitor/Capacitor/UIStatusBarManager+CAPHandleTapAction.m new file mode 100644 index 0000000000..b11f608f82 --- /dev/null +++ b/ios/Capacitor/Capacitor/UIStatusBarManager+CAPHandleTapAction.m @@ -0,0 +1,37 @@ +#import +#import +#import + +@implementation UIStatusBarManager (CAPHandleTapAction) + ++ (void)load { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + Class class = [self class]; + SEL originalSelector = NSSelectorFromString(@"handleTapAction:"); + SEL swizzledSelector = @selector(nofity_handleTapAction:); + + Method originalMethod = class_getInstanceMethod(class, originalSelector); + Method swizzledMethod = class_getInstanceMethod(class, 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)nofity_handleTapAction:(id)arg1 { + [[NSNotificationCenter defaultCenter] postNotification:CAPBridge.statusBarTappedNotification]; + [self nofity_handleTapAction:arg1]; +} + +@end