File tree 1 file changed +17
-1
lines changed
Sources/AccessibilitySnapshot/Core/ObjC
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,23 @@ + (void)AS_setPreferredContentSizeCategoryOverride:(nullable UIContentSizeCatego
55
55
56
56
- (UITraitCollection *)AS_traitCollection ;
57
57
{
58
- UITraitCollection *traitCollection = [self AS_traitCollection ];
58
+ __block UITraitCollection *traitCollection;
59
+
60
+ if (@available (iOS 15 , *)) {
61
+ // TODO: On iOS 15+ simulators there is a main queue assertion crash.
62
+ // Investigation led us to find there is some UIKit internal code calling traitCollection
63
+ // on a background thread which then causes a UIKit main thread exception (since traitCollection needs to be accessed from main).
64
+ // We have not been able to find a solution for it besides this hack to force the call to happen on the main thread.
65
+ if ([NSThread isMainThread ]) {
66
+ traitCollection = [self AS_traitCollection ];
67
+ } else {
68
+ dispatch_sync (dispatch_get_main_queue (), ^{
69
+ traitCollection = [self AS_traitCollection ];
70
+ });
71
+ }
72
+ } else {
73
+ traitCollection = [self AS_traitCollection ];
74
+ }
59
75
60
76
if (contentSizeCategoryOverride != nil ) {
61
77
UITraitCollection *contentSizeCategoryTraitCollection = [UITraitCollection traitCollectionWithPreferredContentSizeCategory: contentSizeCategoryOverride];
You can’t perform that action at this time.
0 commit comments