Skip to content

Commit

Permalink
fix(ios): implement statusTap for iOS 13 (#2376)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Mar 3, 2020
1 parent f7cd4c0 commit 7cb77c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ios/Capacitor/Capacitor/CAPBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 37 additions & 0 deletions ios/Capacitor/Capacitor/UIStatusBarManager+CAPHandleTapAction.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#import <Capacitor/Capacitor-Swift.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(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

0 comments on commit 7cb77c8

Please sign in to comment.