Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ISSUE-017

WebView界面打不了字

常见表现

启用按键映射的情况下,打不了字。

原因分析

ISSUE-006类似,只不过出问题的地方变成WebKit的WKContentView了。

解决方法

临时解决方法:

右键游戏图标 - 设置 - 键盘映射设置,禁用“按键映射布局” 或 禁用“智能按键映射”。

临时修复代码:

PlayTools NSObject+Swizzle.m

手动发送相关事件广播。

- (BOOL)hook_WKContentView_becomeFirstResponder {
    BOOL ret = [self hook_WKContentView_becomeFirstResponder];
    [[NSNotificationCenter defaultCenter] postNotificationName:UITextFieldTextDidBeginEditingNotification
                                                        object:nil];
    return ret;
}

- (BOOL)hook_WKContentView_resignFirstResponder {
    BOOL ret = [self hook_WKContentView_resignFirstResponder];
    [[NSNotificationCenter defaultCenter] postNotificationName:UITextFieldTextDidEndEditingNotification
                                                        object:nil];
    return ret;
}

[objc_getClass("WKContentView") swizzleInstanceMethod:@selector(becomeFirstResponder) withMethod:@selector(hook_WKContentView_becomeFirstResponder)];
[objc_getClass("WKContentView") swizzleInstanceMethod:@selector(resignFirstResponder) withMethod:@selector(hook_WKContentView_resignFirstResponder)];