1

I'm using DAKeyboardControll on my app . it has a method with name : swizzled_addSubview and implement Like this:

- (void)swizzled_addSubview:(UIView *)subview
 {

if (!subview.inputAccessoryView)
{
    if ([subview isKindOfClass:[UITextField class]])
    {
        UITextField *textField = (UITextField *)subview;
        if ([textField respondsToSelector:@selector(setInputAccessoryView:)])
        {
            UIView *nullView = [[UIView alloc] initWithFrame:CGRectZero];
            nullView.backgroundColor = [UIColor clearColor];
            textField.inputAccessoryView = nullView;
        }
    }
    else if ([subview isKindOfClass:[UITextView class]]) {
        UITextView *textView = (UITextView *)subview;
        if ([textView respondsToSelector:@selector(setInputAccessoryView:)] && [textView respondsToSelector:@selector(isEditable)] && textView.isEditable)
        {
            UIView *nullView = [[UIView alloc] initWithFrame:CGRectZero];
            nullView.backgroundColor = [UIColor clearColor];
            textView.inputAccessoryView = nullView;
        }
    }
}
[self swizzled_addSubview:subview];  

}

problem

recently in my new version that compatible with AutoLayout , i receive some crash on this method , and reasons of them : -[UIView(DAKeyboardControl) swizzled_addSubview:] , EXC_BAD_ACCESS KERN_PROTECTION_FAILURE at 0x0090dffc

i know this problem has happened for many many call , but why it can't work correctly ?

this crash happened only for 8 users for 54 times , 50 % of them has a jailbreak Device , but another person has a non- jailbreak Device !

Mo Farhand
  • 1,144
  • 8
  • 21

2 Answers2

0

Method swizzling causes issues at run time. I also got same kind of exception, To get rid of this, I have used BABFrameObservingInputAccessoryView, which is working fine for me. https://github.com/brynbodayle/BABFrameObservingInputAccessoryView

Aaina Jain
  • 353
  • 1
  • 8
0

Most likely your method isn't actually swizzled, so you get a recursive call which will obviously crash. That's the tricky thing about swizzling: It exchanges two methods, so every call to addSubview would call swizzled_addSubview and the call to swizzled_addSubview actually calls addSubview.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
  • 1
    tnx for your reply , but why did you say my method isn't actually swizzled ? can you explain more about this issue ? did you see the class of DAKeyboard ? – Mo Farhand Oct 13 '15 at 10:04