ios - 点击文本字段、关闭键盘并再次点击文本字段时 UIWebView 崩溃

标签 ios cocoa-touch uiwebview

我的应用支持来自多个云服务(Dropbox、Google Drive 等)的授权,并使用适当的 SDK。每个 SDK 通过呈现 Web View 来提供授权,用户可以在其中输入他们的凭据。问题是 WebView 在以下情况下会导致应用程序崩溃:

  1. 呈现 WebView
  2. 点击任何文本框
  3. 出现键盘,按“完成”按钮
  4. 点击您在第 2 步中点击的文本字段
  5. 崩溃

以下信息打印到控制台。

2017-03-22 19:17:55.564 MyApplicationName[46315:16017957] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010e63ff65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000111960deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010e506f55 -[__NSArrayM insertObject:atIndex:] + 901
    3   UIKit                               0x000000011206fcd4 -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 541
    4   UIKit                               0x00000001127e9581 -[UIInputWindowController changeToInputViewSet:] + 1420
    5   UIKit                               0x00000001127e218f -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 369
    6   UIKit                               0x00000001127ea01b -[UIInputWindowController setInputViewSet:] + 983
    7   UIKit                               0x00000001127e1e17 -[UIInputWindowController performOperations:withAnimationStyle:] + 50
    8   UIKit                               0x00000001124fb397 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1275
    9   UIKit                               0x00000001120e0c89 -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 81
    10  UIKit                               0x0000000112527604 -[UIWebBrowserView _reloadInputViewsAfterPotentialFocusRedirect] + 54
    11  UIKit                               0x00000001125274a9 -[UIWebBrowserView _endAllowingFocusRedirects] + 45
    12  libdispatch.dylib                   0x00000001149d149b _dispatch_client_callout + 8
    13  libdispatch.dylib                   0x00000001149bacd8 _dispatch_barrier_sync_f_slow_invoke + 284
    14  libdispatch.dylib                   0x00000001149d149b _dispatch_client_callout + 8
    15  libdispatch.dylib                   0x00000001149b934b _dispatch_main_queue_callback_4CF + 1738
    16  CoreFoundation                      0x000000010e5a03e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    17  CoreFoundation                      0x000000010e561939 __CFRunLoopRun + 2073
    18  CoreFoundation                      0x000000010e560e98 CFRunLoopRunSpecific + 488
    19  GraphicsServices                    0x0000000115eafad2 GSEventRunModal + 161
    20  UIKit                               0x0000000111ee0676 UIApplicationMain + 171
    21  MyApplicationName                   0x000000010c161682 main + 114
    22  libdyld.dylib                       0x0000000114a0592d start + 1
    23  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

显然,问题出现在点击文本字段时,因此我决定通过简单地打开 google.com 并点击那里的文本字段来测试它,以确保应用程序会崩溃。 该应用程序没有崩溃,但它确实在我显示/隐藏键盘时打印了以下信息。

2017-03-22 20:31:52.453 MyApplicationName[55324:16092779] *** WebKit discarded an uncaught exception in the webView:elementDidFocusNode: delegate: <NSInvalidArgumentException> *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
2017-03-22 20:31:54.985 MyApplicationName[55324:16092779] *** WebKit discarded an uncaught exception in the webView:elementDidBlurNode: delegate: <NSInvalidArgumentException> *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
2017-03-22 20:31:56.341 MyApplicationName[55324:16092779] *** WebKit discarded an uncaught exception in the webView:elementDidFocusNode: delegate: <NSInvalidArgumentException> *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
2017-03-22 20:31:58.029 MyApplicationName[55324:16092779] *** WebKit discarded an uncaught exception in the webView:elementDidBlurNode: delegate: <NSInvalidArgumentException> *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
2017-03-22 20:32:00.675 MyApplicationName[55324:16092779] *** WebKit discarded an uncaught exception in the webView:elementDidFocusNode: delegate: <NSInvalidArgumentException> *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
2017-03-22 20:32:02.872 MyApplicationName[55324:16092779] *** WebKit discarded an uncaught exception in the webView:elementDidBlurNode: delegate: <NSInvalidArgumentException> *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil

我怀疑键盘的工具栏有问题,因为如果你看一下 this gif ,您会注意到工具栏第一次出现,但第二次没有出现,QuickType 出现了一小会儿。

附加信息: – 我无法在示例项目中重现该问题,即当我尝试使 google.com 上的应用程序崩溃时,日志中没有崩溃或错误。 - 我不太可能在 UIWindow 上有一些手势识别器,在那里检查过。

所以问题是:我该如何解决这个问题?

最佳答案

在您的 UIInputWindowController 中,在 changeToInputViewSet 中,您尝试添加一个 subview Controller ,但该 subview Controller 为 nil。找出为什么你的 View Controller 是零,并修复它。您有一个揭示崩溃的可重复序列。在 changeToInputViewSet 的开头放置一个断点,并逐步查看您正在使用的任何 viewController 的值。这是你的错误。

关于ios - 点击文本字段、关闭键盘并再次点击文本字段时 UIWebView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42955137/

相关文章:

IOS WebView App - 不同屏幕尺寸的不同 View

ios - 如何在 Swift 中使用 UIImageView 设置背景图片

iOS 相当于 macappstore ://showUpdatesPage

ios - 在 IOS 中使用 DatePicker 而不是键盘的两个单独的文本字段

iphone - 如何以编程方式访问 Nib 中的各种 UIView?

iphone - 更正 float

ios - 用于在页面上显示的 UIPageViewControlerDataSource 和 UiWebView

iPhone - 当用户触摸状态栏时,使 UIWebView subview 滚动到顶部(iOS 4)

ios - SwiftyJSON 打印字典数组中的所有值

ios - 如何覆盖 Swift 委托(delegate)方法以获取更多参数?