如何“撤消” iOS问题?

时间:2019-05-30 21:52:13

标签: ios objective-c swizzle

我正在创建要与HID键盘楔形扫描仪一起使用的应用程序。由于屏幕上的键盘不会弹出并覆盖屏幕,因此我在第一个字段中实现了自动对焦功能。我还进行了切换设置,以尝试“撤消”方法的混乱。当关闭切换时,我正在调用相同的imp_implementationWithBlock方法,但是参数为false而不是true。该字段不会自动对焦,这是预期的,但是选择文本输入后,键盘将不再显示。

+ (void)allowDisplayingKeyboardWithoutUserAction {

    Class class = NSClassFromString(@"WKContentView");
    NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0};
    NSOperatingSystemVersion iOS_12_2_0 = (NSOperatingSystemVersion){12, 2, 0};
    char * methodSignature = "_startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:";

        if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_12_2_0]) {
            methodSignature = "_elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:";
        }
        if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_11_3_0]) {

            SEL selector = sel_getUid(methodSignature);
            Method method = class_getInstanceMethod(class, selector);
            IMP original = method_getImplementation(method);
            IMP override;

            override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, BOOL arg3, id arg4) {
                DDLogVerbose(@"%s - %s",__PRETTY_FUNCTION__, AppDelegate.allowSelectingHTMLTextFieldsWithoutUserTap ? "YES" : "@NO");
                ((void (*)(id, SEL, void*, BOOL, BOOL, BOOL, id))original)(me, selector, arg0, AppDelegate.allowSelectingHTMLTextFieldsWithoutUserTap, arg2, arg3, arg4); // allowInputSelectionWithoutUserTouch
            });

            if(!AppDelegate.allowSelectingHTMLTextFieldsWithoutUserTap){
                imp_removeBlock(override);
            }
            else{
                method_setImplementation(method, override);
            }


        }
        else {
            SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:");
            Method method = class_getInstanceMethod(class, selector);
            IMP original = method_getImplementation(method);
            IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) {
                BOOL allowSwizzle = AppDelegate.allowSelectingHTMLTextFieldsWithoutUserTap;
                ((void (*)(id, SEL, void*, BOOL, BOOL, id))original)(me, selector, arg0, allowSwizzle, arg2, arg3);
            });

            method_setImplementation(method, override);
        }
}

在这里,我尝试使用imp_removeBlock删除该块。我也曾尝试调用method_setImplementation(method,original)没有成功。有什么想法吗?

0 个答案:

没有答案