Я создаю приложение, которое будет использоваться со сканером клина HID клавиатуры.Я включил swizzle, чтобы разрешить автофокус в первом поле, так как экранная клавиатура не будет всплывать и закрывать экран.Я также сделал настройку переключателя, чтобы попытаться «отменить» метод метода.Когда я выключаю swizzle, я вызываю тот же метод 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 (метод, оригинал), но безуспешно.Есть идеи?