26

I am getting the follow crash in my reports but I don't have a clue as to where to start looking! - any help appreciated. I have no calls or reference to UIKeyboardLayoutAlignmentView

        Fatal Exception: NSInternalInconsistencyException
        The layout constraints still need update after sending -updateConstraints
        to <_UIKeyboardLayoutAlignmentView: 0x14df2550; frame = (0 0; 0 0);
    userInteractionEnabled = NO; layer = <CALayer: 0x1603de90>>.
 _UIKeyboardLayoutAlignmentView or one of its superclasses may
        have overridden -updateConstraints without calling super. 
        Or, something may have dirtied layout constraints in the middle
        of updating them. Both are programming errors.
Thread : Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x32d52df0 __pthread_kill + 8
1  libsystem_pthread.dylib        0x32dd1cc7 pthread_kill + 62
2  libsystem_c.dylib              0x32cee909 abort + 76
3  libc++abi.dylib                0x3201c9c9 __cxa_bad_cast
4  libc++abi.dylib                0x32036671 default_unexpected_handler()
5  libobjc.A.dylib                0x326fcf25 _objc_terminate() + 192
6  libc++abi.dylib                0x32033de3 std::__terminate(void (*)()) + 78
7  libc++abi.dylib                0x320338af __cxa_rethrow + 102
8  libobjc.A.dylib                0x326fcdd3 objc_exception_rethrow + 42
9  CoreFoundation                 0x240bf29d CFRunLoopRunSpecific + 632
10 CoreFoundation                 0x240bf013 CFRunLoopRunInMode + 106
11 GraphicsServices               0x2b99e201 GSEventRunModal + 136
12 UIKit                          0x27863a59 UIApplicationMain + 1440


Thread : Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x241aefef __exceptionPreprocess + 126
1  libobjc.A.dylib                0x326fcc8b objc_exception_throw + 38
2  CoreFoundation                 0x241aef35 -[NSException initWithCoder:]
3  UIKit                          0x27e34dad -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 448
4  UIKit                          0x27e34ec3 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 126
5  CoreFoundation                 0x240bec6d CFArrayApplyFunction + 36
6  UIKit                          0x27e34c75 -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 136
7  UIKit                          0x27e34ec3 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 126
8  CoreFoundation                 0x240bec6d CFArrayApplyFunction + 36
9  UIKit                          0x27e34c75 -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 136
10 UIKit                          0x27e34ec3 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 126
11 UIKit                          0x278f0a39 __60-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]_block_invoke + 84
12 Foundation                     0x24e65755 -[NSISEngine withBehaviors:performModifications:] + 256
13 UIKit                          0x278f0813 -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 206
14 UIKit                          0x2790a663 -[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded] + 86
15 UIKit                          0x27e35159 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 172
16 UIKit                          0x27813d97 -[UIView(Hierarchy) layoutBelowIfNeeded] + 542
17 UIKit                          0x27c77a2b -[_UIAlertControllerAnimatedTransitioning animateTransition:] + 690
18 UIKit                          0x27adb08d __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 1820
19 UIKit                          0x2787ea91 _applyBlockToCFArrayCopiedToStack + 308
20 UIKit                          0x277f938f _afterCACommitHandler + 466
21 CoreFoundation                 0x24174fed __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
22 CoreFoundation                 0x241726ab __CFRunLoopDoObservers + 278
23 CoreFoundation                 0x24172ab3 __CFRunLoopRun + 914
24 CoreFoundation                 0x240bf201 CFRunLoopRunSpecific + 476
25 CoreFoundation                 0x240bf013 CFRunLoopRunInMode + 106
26 GraphicsServices               0x2b99e201 GSEventRunModal + 136
27 UIKit                          0x27863a59 UIApplicationMain + 1440
Chris
  • 1,637
  • 1
  • 14
  • 20
  • This is on a live app, and yes they are all iOS8.3 users – Chris Apr 15 '15 at 06:25
  • https://devforums.apple.com/message/1124670#1124670 , says it happens on certain UIAlertView styles. Going to look into it – Chris Apr 15 '15 at 06:28
  • Ok found the problem, now time for the solution. If you have the keyboard displayed and then you bring up an UIAlertView or UIAlertController which then tries to open another keyboard it crashes. I feel a simple force all keyboards close will fix it – Chris Apr 15 '15 at 09:09

4 Answers4

48

Ok, problem found an fixed. On iOS8.3 if you the keyboard is being displayed and then you try to display a UIAlertView or UIAlertController that has an input field you will get this crash.

Simple solution (for me) was to insert

[self.window endEditing:YES]; 

or

[self.view endEditing:YES];

in front of any alerts that do this and it no longer crashes

Update

In some cases I have also needed the following line (as outlined by Oren below), with the endEditing AND this line I have zero issues - but with one OR the other I have seen the odd crash which is weird - but the combo attack seems to work !

UITextField *txtEmail = [alertView textFieldAtIndex:0];
[txtEmail becomeFirstResponder];
Chris
  • 1,637
  • 1
  • 14
  • 20
  • Immediately before presenting the UIAlertController? Or before adding the textfield? – Michael Apr 16 '15 at 23:55
  • Do you have also blinking keyboard now? – Eugen Martynov Apr 28 '15 at 14:54
  • Not that I have witnessed – Chris Apr 28 '15 at 18:23
  • blinking keyboard is a result of endEditing (i.e. resignFirstResponder) just to assign the first responder again to the alert. I posted an answer below that solves this problem without blinking the keyboard – Oren May 29 '15 at 15:36
  • Even when I put `-[UIWindow endEditing:]` before `-[UIAlertView show]`, I still got the crash. I had to wait until I received the `UIKeyboardDidHide` notification before calling `-[UIAlertView show]`. – Heath Borders Aug 17 '15 at 22:33
14

This is definitely a bug with iOS8.3 when showing a UIAlertView or UIAlertController when the keyboard is already shown.

A workaround is to assign the alert view's textfield as the first responder. This works better than hiding the keyboard via resignFirstResponder or endEditing because the keyboard won't flicker.

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle.......
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;

UITextField *txtEmail = [alertView textFieldAtIndex:0];
[txtEmail becomeFirstResponder];

[alertView show];
Oren
  • 5,055
  • 3
  • 34
  • 52
2

This might help someone with the same issue. I came here to check out your answer, but it didn't work for me.

iOS 8.3 UIAlertController crashes when trying to add a textfield

To reiterate what's on the other thread, I solved it by setting the animated flag to "NO" when presenting the UIAlertController

[self presentViewController:alert animated:NO completion:nil];
Community
  • 1
  • 1
Michael
  • 3,269
  • 2
  • 23
  • 16
2

I had the same issue using the Cordova Dialogs plugin in an Ionic app. It seems as of iOS 8.3 whenever a notification or alert is called and the keyboard is already visible, it tries to open another keyboard which causes the crash. I added this one line to the CDVNotification.m file in the plugin.

 if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) {
    alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField* textField = [alertView textFieldAtIndex:0];
    **[textField becomeFirstResponder];** //added this line to Fix :)
    textField.text = defaultText;
}
Alex Chance
  • 783
  • 4
  • 16