4

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally a view controller <_SFAppAutoFillPasswordViewController: 0x106e22ee0> that is already being presented by <UIKeyboardHiddenViewController_Autofill: 0x106e25a10>.'

IOS16(not sure other OS version could reproduce this or not) click on textfield, then keyboard shows(with a key button above), click key button, it crashes randomly.

Bruce
  • 51
  • 1

1 Answers1

0

//IQKeyBoardManager IssuesThe violence has been solved. There is a problem with the tripartite database and the system

#import "UIViewController+PresentKBHook.h"

@implementation UIViewController (PresentKBHook)

+ (void)load {

[UIViewController ff_swizzleInstanceMethodWithSrcClass:[UIViewController class] srcSel:@selector(presentViewController:animated:completion:) swizzledSel:@selector(cr_presentViewController:animated:completion:)];

}

- (void)cr_presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {

if (self.presentedViewController) {
    NSLog(@"[present devil]self=%@,toPresent=%@",self.description, viewControllerToPresent.description);
}else{
    [self cr_presentViewController:viewControllerToPresent animated:flag completion:completion];
}

}

//Implementation of exchanging two object methods

+ (void)ff_swizzleInstanceMethodWithSrcClass:(Class)srcClass srcSel:(SEL)srcSel swizzledSel:(SEL)swizzledSel{

Method srcMethod = class_getInstanceMethod(srcClass, srcSel);
Method swizzledMethod = class_getInstanceMethod(srcClass, swizzledSel);
if (!srcClass || !srcMethod || !swizzledMethod) return;

//Add a layer of protection measures. If the method is added successfully, it means that the method does not exist in this class, but exists in the parent class, and the method of the parent class cannot be exchanged, otherwise the method will crash when the parent class object calls the method; Adding failure indicates that the method exists in this class
BOOL addMethod = class_addMethod(srcClass, srcSel, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (addMethod){
    //After the IMP is successfully implemented by adding methods, the original implementation will be replaced with the swizzledMethod method to achieve method exchange without affecting the implementation of the parent method
    class_replaceMethod(srcClass, swizzledSel, method_getImplementation(srcMethod), method_getTypeEncoding(srcMethod));
}else{
    //Adding failed, calling the implementation of the two interactive methods
    method_exchangeImplementations(srcMethod, swizzledMethod);
}

}

@end

xiaobi
  • 1
  • 1