Workaround random UIViewControllerHierarchyInconsistency crashes
This commit is contained in:
1 parent
02a835685d
commit
503aa827a9
1 file changed
+19
@@ -8,6 +8,7 @@ void swizzle(Class class, SEL originalAction, SEL swizzledAction) {
|
|||||||
|
|
||||||
__attribute__((constructor)) void hookConstructor(void) {
|
__attribute__((constructor)) void hookConstructor(void) {
|
||||||
swizzle(UIDevice.class, @selector(userInterfaceIdiom), @selector(hook_userInterfaceIdiom));
|
swizzle(UIDevice.class, @selector(userInterfaceIdiom), @selector(hook_userInterfaceIdiom));
|
||||||
|
swizzle(UIResponder.class, @selector(becomeFirstResponder), @selector(hook_becomeFirstResponder));
|
||||||
swizzle(UIToolbar.class, @selector(sizeThatFits:), @selector(hook_sizeThatFits:));
|
swizzle(UIToolbar.class, @selector(sizeThatFits:), @selector(hook_sizeThatFits:));
|
||||||
swizzle(UIView.class, @selector(didMoveToSuperview), @selector(hook_didMoveToSuperview));
|
swizzle(UIView.class, @selector(didMoveToSuperview), @selector(hook_didMoveToSuperview));
|
||||||
swizzle(UIView.class, @selector(setFrame:), @selector(hook_setFrame:));
|
swizzle(UIView.class, @selector(setFrame:), @selector(hook_setFrame:));
|
||||||
@@ -36,6 +37,24 @@ __attribute__((constructor)) void hookConstructor(void) {
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation UIResponder(hook)
|
||||||
|
|
||||||
|
- (BOOL)hook_becomeFirstResponder {
|
||||||
|
// Workaround a weird bug: UIKit tries to present an accessibility UITextField
|
||||||
|
// for some reason, which could cause crash due to mismatched parent view controller
|
||||||
|
// UIViewControllerHierarchyInconsistency
|
||||||
|
|
||||||
|
@try {
|
||||||
|
return [self hook_becomeFirstResponder];
|
||||||
|
} @catch (NSException *e) {
|
||||||
|
NSLog(@"-[UITextInputUIResponderAccessibility becomeFirstResponder]: %@", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation UITraitCollection(hook)
|
@implementation UITraitCollection(hook)
|
||||||
|
|
||||||
- (UIUserInterfaceSizeClass)verticalSizeClass {
|
- (UIUserInterfaceSizeClass)verticalSizeClass {
|
||||||
|
|||||||
Reference in new issue
Block a user