Last active
February 1, 2019 01:27
-
-
Save Pranit-Harekar/87dffe9e20897c409e3afec5407cc7a7 to your computer and use it in GitHub Desktop.
Add keyboardRequiresUserInteraction to WKWebViews iOS 11.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import WebKit | |
typealias ClosureType = @convention(c) (Any, Selector, UnsafeRawPointer, Bool, Bool, Bool, Any?) -> Void | |
extension WKWebView{ | |
var keyboardDisplayRequiresUserAction: Bool? { | |
get { | |
return self.keyboardDisplayRequiresUserAction | |
} | |
set { | |
self.setKeyboardRequiresUserInteraction(newValue ?? true) | |
} | |
} | |
func setKeyboardRequiresUserInteraction( _ value: Bool) { | |
if #available(iOS 11.3, *) { | |
let WKContentView: AnyClass = NSClassFromString("WKContentView")! | |
let sel: Selector = | |
sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:") | |
let method = class_getInstanceMethod(WKContentView, sel) | |
let originalImp: IMP = method_getImplementation(method) | |
let original: ClosureType = unsafeBitCast(originalImp, to: ClosureType.self) | |
let block : @convention(block) (Any, UnsafeRawPointer, Bool, Bool, Bool, Any?) -> Void = { (me, arg0, arg1, arg2, arg3, arg4) in | |
original(me, sel, arg0, !value, arg2, arg3, arg4) | |
} | |
let imp: IMP = imp_implementationWithBlock(block) | |
method_setImplementation(method, imp) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it doesn't work for me
in ios9, keybaord appear and then dismiss automatically.
in ios11, keyboard doesn't appear.