Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed infinite loop in workaroundUITextInputTraitsPropertiesBug #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions DCIntrospect/DCIntrospect.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,27 @@ + (void)workaroundUITextInputTraitsPropertiesBug
for (unsigned int i = 0; i < count; i++)
{
Class class = classes[i];
if (class_getInstanceMethod(class, NSSelectorFromString(@"textInputTraits")))
{
if (class_getInstanceMethod(class, NSSelectorFromString(@"textInputTraits"))) {
IMP originalValueForKey = class_replaceMethod(class, @selector(valueForKey:), (IMP)UITextInputTraits_valueForKey, valueForKeyTypeEncoding);
if (!originalValueForKey)
originalValueForKey = (IMP)[objc_getAssociatedObject([class superclass], originalValueForKeyIMPKey) pointerValue];
if (!originalValueForKey)
originalValueForKey = class_getMethodImplementation([class superclass], @selector(valueForKey:));

objc_setAssociatedObject(class, originalValueForKeyIMPKey, [NSValue valueWithPointer:(void *)originalValueForKey], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}
Class superclass = [class superclass];

if (!originalValueForKey)
originalValueForKey = (IMP)[objc_getAssociatedObject(superclass, originalValueForKeyIMPKey) pointerValue];
if (!originalValueForKey)
originalValueForKey = class_getMethodImplementation(superclass, @selector(valueForKey:));

while (originalValueForKey == (IMP)UITextInputTraits_valueForKey) {
superclass = [superclass superclass];
if (!superclass) {
originalValueForKey = method_getImplementation(valueForKey);
break;
}
originalValueForKey = class_getMethodImplementation(superclass, @selector(valueForKey:));
}

objc_setAssociatedObject(class, originalValueForKeyIMPKey, [NSValue valueWithPointer:(void *)originalValueForKey], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}
free(classes);
}

Expand Down