hackiftekhar / IQKeyboardManager

Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.
MIT License
16.44k stars 2.41k forks source link

Intermittent crash in IQKeyboardManager 6.5.19: -[__NSArrayM insertObject:atIndex:]: object cannot be nil #2080

Open qius-code opened 4 days ago

qius-code commented 4 days ago

Description: We are experiencing an intermittent crash in our production app when using IQKeyboardManager. The crash occurs seemingly randomly when a text field begins editing, specifically within the IQKeyboardManager's handling of keyboard toolbar addition. We have not been able to reproduce this issue consistently in our development environment.

Environment:

Crash Details: Exception Type: NSInvalidArgumentException Exception Message: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil

Stack Trace: 0 CoreFoundation _exceptionPreprocess + 164 1 libobjc.A.dylib objc_exception_throw + 88 2 CoreFoundation -[NSArrayM insertObject:atIndex:] + 1276 3 UIKitCore +[UIKeyboardImpl uniqueNumberPadInputModesFromInputModes:forKeyboardType:] + 1524 4 UIKitCore -[_UIKeyboardStateManager desirableInputModesWithExtensions:] + 1088 5 UIKitCore -[_UIKeyboardStateManager recomputeActiveInputModesWithExtensions:allowNonLinguisticInputModes:] + 188 6 UIKitCore -[_UIKeyboardStateManager _setupDelegate:delegateSame:hardwareKeyboardStateChanged:endingInputSessionIdentifier:force:delayEndInputSession:] + 1800 7 UIKitCore -[_UIKeyboardStateManager setDelegate:force:delayEndInputSession:] + 632 8 UIKitCore -[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:] + 2932 9 UIKitCore -[UIKeyboardSceneDelegate _reloadInputViewsForResponder:force:fromBecomeFirstResponder:] + 88 10 UIKitCore -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 84 11 IQKeyboardManager -[UIView(IQToolbarAddition) addKeyboardToolbarWithTarget:titleText:rightBarButtonConfiguration:previousBarButtonConfiguration:nextBarButtonConfiguration:] + 2960 12 IQKeyboardManager -[IQKeyboardManager addToolbarIfRequired] + 756 13 IQKeyboardManager -[IQKeyboardManager textFieldViewDidBeginEditing:] + 440 14 CoreFoundation _CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 148

Additional Information:

Steps to Reproduce: Unfortunately, we don't have consistent steps to reproduce this issue. It appears to occur randomly when users interact with text fields in the app.

Questions:

  1. Are there any known issues with IQKeyboardManager 6.5.19 on iOS 18.0 or with the iPhone 15 Pro that could lead to this type of crash?
  2. Do you have any suggestions for additional debugging steps or logging we could implement to gather more information about this crash when it occurs in production?
  3. Are there any specific IQKeyboardManager configurations or best practices that might help prevent this type of issue?
  4. Given that this is an intermittent issue in production, do you have any recommendations for safeguards or error handling we could implement to prevent crashes even if this error occurs?

We appreciate any insights or assistance you can provide in helping us understand and resolve this intermittent crash. Thank you for your time and for maintaining this valuable library.

hackiftekhar commented 3 days ago

By looking at the crash report, it looks like the crash occurs due to UIKitCore. If the crash was happen due to IQKeyboardManager then [__NSArrayM insertObject:atIndex:] should have been appeared somewhere just near the IQKeyboardManager logs.

Answers:

  1. As far as my knowledge, I don't remember same crash with around same logs, however there were previous issues related to crash due to arrays but not exactly the same.
  2. As I feels like this is probably an iOS issue so I can't provide any debugging suggestions for it, because from the library side, looks like we are doing everything correctly.
  3. Nope, I don't think this is something related to any IQKeyboardManager configuration.
  4. I would recommend to try out upgraded version of the library because sometimes a slight code changes may tweak things to iOS.

Thank you for your kind words. I feel very good when I listen these love towards library.