iOS 9键盘:此应用程序正在从后台线程修改autolayout引擎,这可能导致引擎损坏和奇怪的崩溃

时间:2015-09-25 09:21:47

标签: ios webview keyboard ios9

当我从嵌入在webview中的文本视图启动第三方键盘时,它有时会导致应用程序崩溃。

当应用程序崩溃时可以找到一些证据:

  1. 总是会出现如下警告,但是当键盘显示成功时,也会显示警告。
  2. "" Sep 25 16:44:09 iPhone6-golden XXX [2916]:此应用程序正在从后台线程修改autolayout引擎,这可能导致引擎损坏和奇怪的崩溃。这将在将来的版本中引发异常。""

    Stack:(
            0   CoreFoundation                      0x00000001836f4f74 <redacted> + 148
            1   libobjc.A.dylib                     0x00000001982e7f80 objc_exception_throw + 56
            2   CoreFoundation                      0x00000001836f4ea4 <redacted> + 0
            3   Foundation                          0x000000018470e5d8 <redacted> + 88
            4   Foundation                          0x0000000184594f3c <redacted> + 56
            5   Foundation                          0x0000000184590afc <redacted> + 260
            6   UIKit                               0x0000000188d4f958 <redacted> + 64
            7   UIKit                               0x0000000188d50470 <redacted> + 244
            8   UIKit                               0x0000000188d6cf44 <redacted> + 108
            9   UIKit                               0x0000000189476798 <redacted> + 268
            10  UIKit                               0x0000000188f4dfcc <redacted> + 176
            11  UIKit                               0x0000000188f3d0b4 <redacted> + 52
            12  UIKit                               0x0000000188c4700c <redacted> + 644
            13  QuartzCore                          0x000000018844df14 <redacted> + 148
            14  QuartzCore                          0x0000000188448b20 <redacted> + 292
            15  QuartzCore                          0x00000001884489e0 <redacted> + 32
            16  QuartzCore                          0x000000018844807c <redacted> + 252
            17  QuartzCore                          0x0000000188447dd0 <redacted> + 516
            18  QuartzCore                          0x0000000188476f48 <redacted> + 236
            19  libsystem_pthread.dylib             0x0000000198cf61e8 <redacted> + 584
            20  libsystem_pthread.dylib             0x0000000198cf5d60 <redacted> + 136
            21  libsystem_pthread.dylib             0x0000000198cf7b48 pthread_sigmask + 0
            22  libsystem_pthread.dylib             0x0000000198cf7aa0 <redacted> + 0
            23  libsystem_pthread.dylib             0x0000000198cf5030 thread_start + 4
        )
    
    1. 应用程序崩溃了,而不是键盘。您可以在Xcode的设备日志中找到回溯。

      异常类型:EXC_CRASH(SIGABRT) 例外代码:0x0000000000000000,0x0000000000000000 例外注意:EXC_CORPSE_NOTIFY 线程触发:18 过滤的系统日志: 找不到

      Last Exception Backtrace:
      0   CoreFoundation                  0x183f20f5c __exceptionPreprocess + 124
      1   libobjc.A.dylib                 0x198b13f80 objc_exception_throw + 56
      2   CoreFoundation                  0x183f20e2c +[NSException raise:format:arguments:] + 108
      3   Foundation                      0x184e0ff3c -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112
      4   UIKit                           0x1897130e8 -[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] + 200
      5   UIKit                           0x1897131ac -[UIApplication _systemAnimationFenceCreatingIfNecessary:] + 24
      6   UIKit                           0x1897653cc +[UIWindow _synchronizedDrawingFence] + 116
      7   UIKit                           0x189c137a4 -[_UIRemoteViewController synchronizeAnimationsInActions:] + 124
      8   UIKit                           0x189c0e158 -[_UISizeTrackingView _geometryChanges:forAncestor:] + 540
      9   UIKit                           0x189775fc8 -[UIView _notifyGeometryObserversWithChangeInfo:] + 272
      10  UIKit                           0x1894d36b4 -[UIView setCenter:] + 408
      11  UIKit                           0x18957ea40 -[UIView(Geometry) _applyISEngineLayoutValues] + 600
      12  UIKit                           0x18948e6b8 -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 136
      13  CoreFoundation                  0x183e17ab0 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 132
      14  CoreFoundation                  0x183e179a8 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 308
      15  UIKit                           0x18947d3e8 -[UIView(Geometry) resizeSubviewsWithOldSize:] + 116
      16  UIKit                           0x18957eb88 -[UIView(AdditionalLayoutSupport) _is_layout] + 128
      17  UIKit                           0x18977a210 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 756
      18  UIKit                           0x18947300c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 644
      19  QuartzCore                      0x188c79f14 -[CALayer layoutSublayers] + 148
      20  QuartzCore                      0x188c74b20 CA::Layer::layout_if_needed(CA::Transaction*) + 292
      21  QuartzCore                      0x188c749e0 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
      22  QuartzCore                      0x188c7407c CA::Context::commit_transaction(CA::Transaction*) + 252
      23  QuartzCore                      0x188c73dd0 CA::Transaction::commit() + 516
      24  QuartzCore                      0x188c6d4bc CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80
      25  CoreFoundation                  0x183ed7c30 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
      26  CoreFoundation                  0x183ed59d4 __CFRunLoopDoObservers + 372
      27  CoreFoundation                  0x183e04de0 CFRunLoopRunSpecific + 416
      28  WebCore                         0x195a69aa0 RunWebThread(void*) + 456
      29  libsystem_pthread.dylib         0x199523b3c _pthread_body + 156
      30  libsystem_pthread.dylib         0x199523aa0 _pthread_start + 156
      31  libsystem_pthread.dylib         0x199521030 thread_start + 4
      
      Thread 18 name:  WebThread
      Thread 18 Crashed:
      0   libsystem_kernel.dylib          0x000000019945b1e0 __pthread_kill + 8
      1   libsystem_pthread.dylib         0x0000000199524f0c pthread_kill + 112
      2   libsystem_c.dylib               0x00000001993ceb78 abort + 140
      3   libc++abi.dylib                 0x00000001981913f4 __cxa_bad_cast + 0
      4   libc++abi.dylib                 0x00000001981aaf60 std::__terminate(void (*)()) + 44
      5   libc++abi.dylib                 0x00000001981aab10 __cxa_rethrow + 144
      6   libobjc.A.dylib                 0x0000000198b14120 objc_exception_rethrow + 44
      7   CoreFoundation                  0x0000000183e04e68 CFRunLoopRunSpecific + 552
      8   WebCore                         0x0000000195a69aa0 RunWebThread(void*) + 456
      9   libsystem_pthread.dylib         0x0000000199523b3c _pthread_body + 156
      10  libsystem_pthread.dylib         0x0000000199523aa0 _pthread_body + 0
      11  libsystem_pthread.dylib         0x0000000199521030 thread_start + 4
      
    2. 从崩溃堆栈中,很明显应用程序是从WebThread崩溃的,我想它是在显示键盘时更新一些UI细节。

      但是,ios8中的一切都运行良好。*。谁能给我一些关于为什么会这样的建议呢?或者为什么webview与iOS8如此奇怪和不同?我发现苹果公司的文件没有任何变化。

      提前致谢。

2 个答案:

答案 0 :(得分:1)

我发现崩溃问题可能是由三方键盘的启动时间成本引起的。

我做了以下实验,将自定义键盘与快速启动和延迟启动时间成本进行比较。两个实验中唯一的一个变量是启动键盘时间成本。键盘没有任何延迟似乎非常稳定(我的意思是我没有发现任何崩溃),但是当我将键盘延迟大约800ms-1ms时,崩溃的风险迅速增加。

所以我想知道WebThread可能有一些定时器,当你的键盘出现时(这意味着自动布局引擎需要工作),它可能会触发webview崩溃。

答案 1 :(得分:1)

实际上是由第三方键盘引起的。我发现的最佳解决方案是在应用程序中禁用第三方键盘。您可以扩展应用程序委托,并使用以下代码来检测和阻止第三方键盘:

- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier {
if ([extensionPointIdentifier isEqualToString: UIApplicationKeyboardExtensionPointIdentifier]) {
    return NO;
}
return YES;

}