【问题标题】:iOS 11 and up crashing with -[UIView setDrawsWithVibrantLightMode:]: unrecognized selector sent to instanceiOS 11 及更高版本崩溃 -[UIView setDrawsWithVibrantLightMode:]: unrecognized selector sent to instance
【发布时间】:2017-11-17 14:44:06
【问题描述】:

我注意到在 iOS 11 及更高版本中出现此消息的应用崩溃率显着增加。这似乎是 UIKit 正在调用的内部 API,堆栈跟踪显示它在 UITableViewCell 内部:

    Application Specific Information:
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setDrawsWithVibrantLightMode:]: unrecognized selector sent to instance 0x15defa6d0'

    Last Exception Backtrace:
    0   CoreFoundation                       0x0000000181691d04 __exceptionPreprocess + 124
    1   libobjc.A.dylib                      0x00000001808e0528 objc_exception_throw + 52
    2   CoreFoundation                       0x000000018169f1c8 -[NSObject(NSObject) doesNotRecognizeSelector:] + 136
    3   UIKit                                0x000000018ae8711c -[UIResponder doesNotRecognizeSelector:] + 292
    4   CoreFoundation                       0x00000001816976b0 ___forwarding___ + 1376
    5   CoreFoundation                       0x000000018157d01c _CF_forwarding_prep_0 + 88
    6   UIKit                                0x000000018b022d58 -[UITableViewCell _setSeparatorDrawsInVibrantLightMode:] + 216
    7   UIKit                                0x000000018abf5ef0 -[UITableViewCell setSeparatorColor:] + 340
    8   UIKit                                0x000000018abf451c __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 1228
    9   UIKit                                0x000000018aad6e34 +[UIView(Animation) performWithoutAnimation:] + 100
    10  UIKit                                0x000000018abf3f64 -[UITableView _configureCellForDisplay:forIndexPath:] + 268
    11  UIKit                                0x000000018ae03a00 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 844
    12  UIKit                                0x000000018ae03eac -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 76
    13  UIKit                                0x000000018ade39f0 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2136
    14  UIKit                                0x000000018ab99508 -[UITableView layoutSubviews] + 136

我无法重现此问题,但它在许多用户设备上一直崩溃,并且设备或操作系统版本之间没有共同的线程,除了它仅在 iOS 11 及更高版本上发生。

【问题讨论】:

    标签: ios swift uikit


    【解决方案1】:

    最终发现这是UIKit 中的一个错误,当在辅助功能设置下启用深色设置时:

    Settings -> General -> Accessibility -> Increase Contrast -> Darken Colors

    如果您遇到此崩溃,请尝试打开/关闭该设置以重现它。

    现在我们通过简单地将这个方法实现为扩展中的Void 函数来抑制这种情况:

    @available(iOS 11.0, *)
    extension UITableViewCell {
      func _setSeparatorDrawsInVibrantLightMode(_ value: Bool) {
    
      }
    }
    

    所以UIKit 可以调用它,但它什么也不做(并且不会使应用程序崩溃)。

    【讨论】:

    • 您需要将方法标记为@obj 才能使其工作。
    • 感谢您的回答!为此,我在 Swift 4.2 中有“'_setSeparatorDrawsInVibrantLightMode' 的无效重新声明”错误。有什么想法吗?
    • 看起来这不适用于 iOS 12。有什么想法吗?
    【解决方案2】:

    正如 jwswart 在他的回答中所说,应该添加下一个代码:

    @available(iOS 11.0, *)
    extension UITableViewCell {
      @objc func _setSeparatorDrawsInVibrantLightMode(_ value: Bool) {
    
      }
    }
    

    但有时您会收到相同的错误消息,但出现不同的问题。要修复它,您还应该添加:

    @available(iOS 11.0, *)
    extension UITableView {
      @objc func _setSeparatorsDrawInVibrantLightModeUIAppearance(_ value: Bool) {
    
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 1970-01-01
      • 2011-04-01
      相关资源
      最近更新 更多