【问题标题】:Application crashes on iOS 13 because of returned nil from -traitCollection, which is not allowed由于从 -traitCollection 返回的 nil,应用程序在 iOS 13 上崩溃,这是不允许的
【发布时间】:2020-02-04 19:49:28
【问题描述】:

我正在处理来自 archived repo 的 Telegram 源代码,并且应用程序在每个 ViewController 中崩溃,我可以看到以下错误。我还尝试注释掉一些代码,但崩溃只是从一个类转移到另一个类。有什么方法可以阻止traitCollection 导致这些崩溃?

Telegram[50090:787790] *** Assertion failure in UITraitCollection * _Nonnull _UIGetCurrentFallbackTraitCollection(void)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3899.13.13/_UIFallbackEnvironment.m:91
Telegram[50090:787790] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<Decorated498f14ad: 0x7f80e9d46b20; baseClass = UIImageView; frame = (0 0; 8 14); userInteractionEnabled = NO; layer = <CALayer: 0x6000023abc00>> returned nil from -traitCollection, which is not allowed.'

PS:我无法切换到较新版本的 Telegram iOS。

我试过this answer,但没有帮助

我还尝试使用异步调度程序运行我的代码行,但仍然没有变化

First throw call stack:
(
0   CoreFoundation                      0x00007fff23b98bde __exceptionPreprocess + 350
1   libobjc.A.dylib                     0x00007fff503b5b20 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff23b98958 +[NSException raise:format:arguments:] + 88
3   Foundation                          0x00007fff255eb7be -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
4   UIKitCore                           0x00007fff46dd08bd _UIGetCurrentFallbackTraitCollection + 962
5   UIKitCore                           0x00007fff46dce21a +[UITraitCollection _currentTraitCollection] + 196
6   UIKitCore                           0x00007fff476366c6 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2386
7   QuartzCore                          0x00007fff2b030ef9 -[CALayer layoutSublayers] + 255
8   QuartzCore                          0x00007fff2b0358ff _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
9   QuartzCore                          0x00007fff2b041fe4 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
10  QuartzCore                          0x00007fff2af8a4a8 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
11  QuartzCore                          0x00007fff2afbfab3 _ZN2CA11Transaction6commitEv + 643
12  UIKitCore                           0x00007fff4715c27c _UIApplicationFlushRunLoopCATransactionIfTooLate + 104
13  UIKitCore                           0x00007fff471fd878 __handleEventQueueInternal + 6902
14  CoreFoundation                      0x00007fff23afbac1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15  CoreFoundation                      0x00007fff23afb9ec __CFRunLoopDoSource0 + 76
16  CoreFoundation                      0x00007fff23afb1c4 __CFRunLoopDoSources0 + 180
17  CoreFoundation                      0x00007fff23af5ecf __CFRunLoopRun + 1263
18  CoreFoundation                      0x00007fff23af56b6 CFRunLoopRunSpecific + 438
19  GraphicsServices                    0x00007fff3815cbb0 GSEventRunModal + 65
20  UIKitCore                           0x00007fff47162a67 UIApplicationMain + 1621
21  Telegram                            0x000000010bcbb0f4 main + 132
22  libdyld.dylib                       0x00007fff5123bcf5 start + 1
)

【问题讨论】:

    标签: ios objective-c telegram ios13


    【解决方案1】:

    如果是旧的 Telegram 源代码,TGSimpleImageView 会导致这个问题,只需在 traitCollection 函数中放入以下代码而不是 'return nil'

    - (UITraitCollection *)traitCollection
    {
        if (@available(iOS 13.0, *)) {
            [UITraitCollection setCurrentTraitCollection:[[UITraitCollection alloc]init]];
        } else {
            // Fallback on earlier versions
        };
        return [[UITraitCollection alloc]init];
    }
    

    【讨论】:

    • 我没有使用 Telegram,但在我的应用程序中遇到了同样的问题。请建议如何识别此问题。无法理解哪个图书馆给出了这个问题
    • 我看了error的stacktrace,比如你看看上面的stacktrace,你可以看到traitCollection是nil,所以我找了个类似的地方,不知道也许我是幸运找到的-_-
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2019-06-25
    • 2020-02-12
    • 2022-12-19
    • 1970-01-01
    • 2018-12-08
    相关资源
    最近更新 更多