Skip to content

Commit

Permalink
Fix a crash when call twice load method. Fix a custom html provider c…
Browse files Browse the repository at this point in the history
…rash.
  • Loading branch information
HDB-Li committed Nov 7, 2019
1 parent f9bc14a commit 577875c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ - (void)rightItemClick:(UIButton *)sender {
}
Class cls = NSClassFromString(self.webViewClass);

UIViewController *customViewController = [LLConfig shared].htmlViewControllerProvider(urlString);
if (customViewController && cls == [customViewController class]) {
[LLSettingManager shared].lastWebViewUrl = urlString;
[self.navigationController pushViewController:customViewController animated:YES];
return;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if (cls != [UIWebView class] && cls != [WKWebView class]) {
#pragma clang diagnostic pop
if ([LLConfig shared].htmlViewControllerProvider != nil) {
UIViewController *customViewController = [LLConfig shared].htmlViewControllerProvider(urlString);
if (customViewController && cls == [customViewController class]) {
[LLSettingManager shared].lastWebViewUrl = urlString;
[self.navigationController pushViewController:customViewController animated:YES];
return;
}
[[LLToastUtils shared] toastMessage:@"Provider custom webView failed."];
return;
}
[[LLToastUtils shared] toastMessage:@"Invalid webView class"];
return;
}
Expand Down Expand Up @@ -141,9 +144,11 @@ - (void)showWebViewClassAlert {
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[actions addObject:NSStringFromClass([UIWebView class])];
#pragma clang diagnostic pop
UIViewController *vc = [LLConfig shared].htmlViewControllerProvider(nil);
if (vc) {
[actions addObject:NSStringFromClass([vc class])];
if ([LLConfig shared].htmlViewControllerProvider != nil) {
UIViewController *vc = [LLConfig shared].htmlViewControllerProvider(nil);
if (vc) {
[actions addObject:NSStringFromClass([vc class])];
}
}
__weak typeof(self) weakSelf = self;
[self LL_showActionSheetWithTitle:@"Web View Style" actions:actions currentAction:self.webViewClass completion:^(NSInteger index) {
Expand Down
2 changes: 0 additions & 2 deletions LLDebugTool/Core/Component/Network/Function/LLNetworkHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#import "LLConfig.h"
#import "LLTool.h"

#import "NSObject+LL_Runtime.h"

static LLNetworkHelper *_instance = nil;

@interface LLNetworkHelper ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#import "LLConst.h"

#import "UIViewController+LL_Utils.h"
#import "NSObject+LL_Runtime.h"

@interface LLSettingViewController () <UITableViewDataSource>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
@implementation UIView (LLWidgetBorder)

+ (void)load {
[self LL_swizzleInstanceMethodWithOriginSel:@selector(layoutSubviews) swizzledSel:@selector(LL_layoutSubviews)];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[UIView class] LL_swizzleInstanceMethodWithOriginSel:@selector(layoutSubviews) swizzledSel:@selector(LL_layoutSubviews)];
});
}

- (void)LL_layoutSubviews {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
@implementation NSURLSession (LL_Utils)

+ (void)load {
[self LL_swizzleClassMethodWithOriginSel:@selector(sessionWithConfiguration:delegate:delegateQueue:) swizzledSel:@selector(LL_sessionWithConfiguration:delegate:delegateQueue:)];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[NSURLSession class] LL_swizzleClassMethodWithOriginSel:@selector(sessionWithConfiguration:delegate:delegateQueue:) swizzledSel:@selector(LL_sessionWithConfiguration:delegate:delegateQueue:)];
});
}

+ (NSURLSession *)LL_sessionWithConfiguration:(NSURLSessionConfiguration *)configuration delegate:(nullable id <NSURLSessionDelegate>)delegate delegateQueue:(nullable NSOperationQueue *)queue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@
@implementation NSURLSessionConfiguration (LL_Utils)

+ (void)load {
[self LL_swizzleClassMethodWithOriginSel:@selector(defaultSessionConfiguration) swizzledSel:@selector(LL_defaultSessionConfiguration)];

[self LL_swizzleClassMethodWithOriginSel:@selector(ephemeralSessionConfiguration) swizzledSel:@selector(LL_ephemeralSessionConfiguration)];

Class cls = NSClassFromString(@"__NSCFURLSessionConfiguration") ? : NSClassFromString(@"NSURLSessionConfiguration");

Method method1 = class_getInstanceMethod(cls, @selector(protocolClasses));
Method method2 = class_getInstanceMethod([NSURLSessionConfiguration class], @selector(LL_protocolClasses));

[self LL_swizzleMethod:method1 anotherMethod:method2];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[NSURLSessionConfiguration class] LL_swizzleClassMethodWithOriginSel:@selector(defaultSessionConfiguration) swizzledSel:@selector(LL_defaultSessionConfiguration)];

[[NSURLSessionConfiguration class] LL_swizzleClassMethodWithOriginSel:@selector(ephemeralSessionConfiguration) swizzledSel:@selector(LL_ephemeralSessionConfiguration)];

Class cls = NSClassFromString(@"__NSCFURLSessionConfiguration") ? : NSClassFromString(@"NSURLSessionConfiguration");

Method method1 = class_getInstanceMethod(cls, @selector(protocolClasses));
Method method2 = class_getInstanceMethod([NSURLSessionConfiguration class], @selector(LL_protocolClasses));

[[NSURLSessionConfiguration class] LL_swizzleMethod:method1 anotherMethod:method2];
});
}

+ (NSURLSessionConfiguration *)LL_defaultSessionConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
@implementation UIResponder (LL_Utils)

+ (void)load {
[self LL_swizzleInstanceMethodWithOriginSel:@selector(motionBegan:withEvent:) swizzledSel:@selector(LL_motionBegan:withEvent:)];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[UIResponder class] LL_swizzleInstanceMethodWithOriginSel:@selector(motionBegan:withEvent:) swizzledSel:@selector(LL_motionBegan:withEvent:)];
});
}

- (void)LL_motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
Expand Down
5 changes: 4 additions & 1 deletion LLDebugTool/Core/Others/Category/UIView/UIView+LL_Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
@implementation UIView (LL_Utils)

+ (void)load {
[self LL_swizzleInstanceMethodWithOriginSel:@selector(sizeToFit) swizzledSel:@selector(LL_sizeToFit)];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[UIView class] LL_swizzleInstanceMethodWithOriginSel:@selector(sizeToFit) swizzledSel:@selector(LL_sizeToFit)];
});
}

- (void)setLL_horizontalPadding:(CGFloat)LL_horizontalPadding {
Expand Down
19 changes: 11 additions & 8 deletions LLDebugTool/Core/Others/Category/UIWindow/UIWindow+LL_Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
@implementation UIWindow (LL_Utils)

+ (void)load {
// NSString *canAffectSelectorString = @"_canAffectStatusBarAppearance";
// SEL canAffectSelector = NSSelectorFromString(canAffectSelectorString);

NSString *canBecomeKeySelectorString = @"_canBecomeKeyWindow";
SEL canBecomeKeySelector = NSSelectorFromString(canBecomeKeySelectorString);

// [self LL_swizzleInstanceMethodWithOriginSel:canAffectSelector swizzledSel:@selector(_LL_canAffectStatusBarAppearance)];
[self LL_swizzleInstanceMethodWithOriginSel:canBecomeKeySelector swizzledSel:@selector(_LL_canBecomeKeyWindow)];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// NSString *canAffectSelectorString = @"_canAffectStatusBarAppearance";
// SEL canAffectSelector = NSSelectorFromString(canAffectSelectorString);

NSString *canBecomeKeySelectorString = @"_canBecomeKeyWindow";
SEL canBecomeKeySelector = NSSelectorFromString(canBecomeKeySelectorString);

// [[UIWindow class] LL_swizzleInstanceMethodWithOriginSel:canAffectSelector swizzledSel:@selector(_LL_canAffectStatusBarAppearance)];
[[UIWindow class] LL_swizzleInstanceMethodWithOriginSel:canBecomeKeySelector swizzledSel:@selector(_LL_canBecomeKeyWindow)];
});
}

- (UIViewController *)LL_currentShowingViewController {
Expand Down

0 comments on commit 577875c

Please sign in to comment.