File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Sources/AccessibilitySnapshot/Core/ObjC Expand file tree Collapse file tree 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
5555
5656- (UITraitCollection *)AS_traitCollection ;
5757{
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+ }
5975
6076 if (contentSizeCategoryOverride != nil ) {
6177 UITraitCollection *contentSizeCategoryTraitCollection = [UITraitCollection traitCollectionWithPreferredContentSizeCategory: contentSizeCategoryOverride];
You can’t perform that action at this time.
0 commit comments