[CALayer(CALayerPrivate) ancestorSharedWithLayer:]

[CALayer(CALayerPrivate) ancestorSharedWithLayer:] 错误日志:

Crashed: com.apple.main-thread
0 QuartzCore 0x23790 CA::Layer::superlayer(CA::Transaction*) + 28
1 QuartzCore 0xad748 -[CALayer(CALayerPrivate) ancestorSharedWithLayer:] + 112
2 QuartzCore 0x1d010 CA::Layer::map_geometry(CALayer*, CALayer*, void (*)(void*, CA::Mat4<double> const&), void (*)(void*, CA::Mat4<double> const&), void*) + 136
3 QuartzCore 0xc9c94 -[CALayer convertPoint:toLayer:] + 80
4 UIKitCore 0x234cd4 -[UIView(Geometry) convertPoint:toView:] + 112
5 UIAccessibility 0x1b960 -[NSObject(AXPrivCategory) _accessibilityBaseHitTest:withEvent:] + 3416
6 UIKit 0xce494 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 160
7 UIKit 0xa4318 -[UITableViewCellAccessibility _accessibilityHitTest:withEvent:] + 2280
8 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
9 UIKit 0x96cc0 -[UITableViewAccessibility _accessibilityHitTest:withEvent:] + 164
10 PreferencesFramework 0xb6fc (缺少 UUID a69f299d65e639d69a322e24499981e1)
11 UIAccessibility 0x1bd68 __64-[NSObject(AXPrivCategory) _accessibilityBaseHitTest:withEvent:]_block_invoke.274 + 112
12 UIAccessibility 0x1b514 -[NSObject(AXPrivCategory) _accessibilityBaseHitTest:withEvent:] + 2316
13 UIKit 0xce494 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 160
14 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
15 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
16 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
17 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
18 UIKit 0x3f1d4 -[UICollectionViewCellAccessibility _accessibilityHitTest:withEvent:] + 120
19 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
20 UIKit 0x3ae38 -[UICollectionViewAccessibility _accessibilityHitTest:withEvent:] + 228
21 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
22 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
23 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
24 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
25 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
26 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
27 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
28 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
29 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
30 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
31 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
32 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
33 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
34 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
35 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
36 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
37 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
38 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
39 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
40 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
41 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
42 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
43 UIKit 0xccc88 -[UIViewAccessibility __accessibilityHitTest:withEvent:] + 1604
44 UIKit 0xce464 -[UIViewAccessibility _accessibilityHitTest:withEvent:] + 112
45 UIKit 0xd6590 -[UIWindowAccessibility _accessibilityHitTest:withEvent:] + 144
46 UIAccessibility 0x628c _copyElementAtPositionCallback + 1952
47 AXRuntime 0xc7f4 ___AXXMIGCopyElementAtPosition_block_invoke + 72
48 AXRuntime 0xb680 _handleNonMainThreadCallback + 72
49 AXRuntime 0xc67c _AXXMIGCopyElementAtPosition + 268
50 AXRuntime 0x7f48 _AXUIElementCopyElementAtPositionWithParams + 2648
51 UIAccessibility 0x24b44 -[NSObject(AXPrivCategory) _accessibilityVisiblePointHitTestingAnyElement:] + 2852
52 UIAccessibility 0x25020 -[NSObject(AXPrivCategory) _accessibilityIsVisibleByCompleteHitTest:] + 196
53 UIAccessibility 0x30010 -[NSObject(AXPrivCategory) _iosAccessibilityAttributeValue:] + 10488

这个Bug由来已久,崩溃日志每个版本都会有一两个用户,复现好久都没复现出来,看日志信息也不知道咋解决。唯一搜索到相关的是这个 https://www.cocoanetics.com/2013/11/radar-accessibility-based-tools-crash-app-running-in-ios-7-simulator/ ,因为项目中使用DTCoreText ,猜测肯定是自定义View然后丢给 DTCoreText 上渲染引起的。终于捉到一个用户反馈,发来视频,几乎一样的环境系统没发现出来问题,最在无可奈何的时候发现状态栏是昂有个蓝色的话筒,经过一番查找资料,这是iOS系统的辅助功能“语音控制”。

然后在系统 设置 –> 辅助功能 –> 语音控制 –> 关闭时,发现不崩了。

当时也没找到问题所在价加上着急发版,又有很多需求,只让用户关闭语音控制功能。时隔两三年又来用户反馈,缺怎么越记不起怎么操作的,记忆里在衰退了。

后台经过二分法注释代码,发现是自定义的一个 View 上 add 了一个 textField。isAccessibilityElement 默认打开,关闭这个属性即可。

self.textField = [[UITextField alloc] init];
self.textField.isAccessibilityElement = NO;

这里面涉及无障碍框架 UIAccessibility。

又发现新的问题,虽然设置了 view.isAccessibilityElement = NO; 但是在 iOS 16 上又闪退了。

作者给到回复是

I found that this comes from iOS seemingly having a problem with NSProxy. That’s being used to have a stand-in for a custom text attachment view that might be not created yet. It can also be worked around by omitting such a proxy for all text attachments.

Anybody have a custom view that implements accessibility?

So for the time being - until we know better - I’ve just replaced the NSProxy with NSObject. With that the crash doesn’t occur.

大概意思是 NSProxy 引起的,用NSObject替代NSProxy。 但是测试后发现还是有问题。既然没用到 Accessibility 相关方法,就删除了。

fork 了源码,移除了 DTAccessibilityViewProxyDelegate 相关代理事件 https://github.com/duxinfeng/DTCoreText/commit/ebd552e7ac4152f28b62722a71e55b567dbb1ec9

参考链接:

1、https://www.jianshu.com/p/0991a4f0bc0c

2、https://developer.apple.com/documentation/objectivec/nsobject/1615141-isaccessibilityelement?language=objc

3、https://github.com/Cocoanetics/DTCoreText/issues/1272