简体   繁体   中英

Xcode 9.0 Swift 04 (Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!')

Main Thread Checker: UI API called on a background thread: -[UIView init]
PID: 460, TID: 62011, Thread name: (none), Queue name: com.apple.root.background-qos, QoS: 9
Backtrace:
4   IQKeyboardManagerSwift              0x00000001025c8274 _T0So11UITextFieldCABycfcTO + 28
5   IQKeyboardManagerSwift              0x00000001025a8360 _T0So11UITextFieldCABycfC + 68
6   IQKeyboardManagerSwift              0x00000001025a7e90 _T022IQKeyboardManagerSwift0aB0CACycfc + 5196
7   IQKeyboardManagerSwift              0x00000001025a838c _T022IQKeyboardManagerSwift0aB0CACycfcTo + 28
8   IQKeyboardManagerSwift              0x00000001025a6a3c _T022IQKeyboardManagerSwift0aB0CACycfC + 32
9   IQKeyboardManagerSwift              0x00000001025c5920 globalinit_33_1804EA4A44CDC62F5B66EAD58B4692DC_func2 + 24
10  libdispatch.dylib                   0x00000001043e545c _dispatch_client_callout + 16
11  libdispatch.dylib                   0x00000001043e617c dispatch_once_f + 120
12  IQKeyboardManagerSwift              0x000000010259c4cc _T022IQKeyboardManagerSwift0aB0C06sharedB0ACyFZ6StaticL_V02kbB0ACfau + 56
13  IQKeyboardManagerSwift              0x000000010259c46c _T022IQKeyboardManagerSwift0aB0C06sharedB0ACyFZ + 24
14  eBeePartners                        0x0000000100c9ef7c _T012eBeePartners11AppDelegateC11applicationSbSo13UIApplicationC_s10DictionaryVySC0F16LaunchOptionsKeyVypGSg022didFinishLaunchingWithI0tFyycfU_ + 52
15  eBeePartners                        0x0000000100bd18c0 _T0Ix_IyB_TR + 48
16  libdispatch.dylib                   0x00000001043e549c _dispatch_call_block_and_release + 24
17  libdispatch.dylib                   0x00000001043e545c _dispatch_client_callout + 16
18  libdispatch.dylib                   0x00000001043f6cd8 _dispatch_root_queue_drain + 1004
19  libdispatch.dylib                   0x00000001043f6880 _dispatch_worker_thread3 + 136
20  libsystem_pthread.dylib             0x0000000181dab130 _pthread_wqthread + 1268
21  libsystem_pthread.dylib             0x0000000181daac30 start_wqthread + 4
2017-09-22 12:36:11.268059+0800 eBeePartners[460:62011] [reports] Main Thread Checker: UI API called on a background thread: -[UIView init]
PID: 460, TID: 62011, Thread name: (none), Queue name: com.apple.root.background-qos, QoS: 9
Backtrace:
4   IQKeyboardManagerSwift              0x00000001025c8274 _T0So11UITextFieldCABycfcTO + 28
5   IQKeyboardManagerSwift              0x00000001025a8360 _T0So11UITextFieldCABycfC + 68
6   IQKeyboardManagerSwift              0x00000001025a7e90 _T022IQKeyboardManagerSwift0aB0CACycfc + 5196
7   IQKeyboardManagerSwift              0x00000001025a838c _T022IQKeyboardManagerSwift0aB0CACycfcTo + 28
8   IQKeyboardManagerSwift              0x00000001025a6a3c _T022IQKeyboardManagerSwift0aB0CACycfC + 32
9   IQKeyboardManagerSwift              0x00000001025c5920 globalinit_33_1804EA4A44CDC62F5B66EAD58B4692DC_func2 + 24
10  libdispatch.dylib                   0x00000001043e545c _dispatch_client_callout + 16
11  libdispatch.dylib                   0x00000001043e617c dispatch_once_f + 120
12  IQKeyboardManagerSwift              0x000000010259c4cc _T022IQKeyboardManagerSwift0aB0C06sharedB0ACyFZ6StaticL_V02kbB0ACfau + 56
13  IQKeyboardManagerSwift              0x000000010259c46c _T022IQKeyboardManagerSwift0aB0C06sharedB0ACyFZ + 24
14  eBeePartners                        0x0000000100c9ef7c _T012eBeePartners11AppDelegateC11applicationSbSo13UIApplicationC_s10DictionaryVySC0F16LaunchOptionsKeyVypGSg022didFinishLaunchingWithI0tFyycfU_ + 52
15  eBeePartners                        0x0000000100bd18c0 _T0Ix_IyB_TR + 48
16  libdispatch.dylib                   0x00000001043e549c _dispatch_call_block_and_release + 24
17  libdispatch.dylib                   0x00000001043e545c _dispatch_client_callout + 16
18  libdispatch.dylib                   0x00000001043f6cd8 _dispatch_root_queue_drain + 1004
19  libdispatch.dylib                   0x00000001043f6880 _dispatch_worker_thread3 + 136
20  libsystem_pthread.dylib             0x0000000181dab130 _pthread_wqthread + 1268
21  libsystem_pthread.dylib             0x0000000181daac30 start_wqthread + 4
2017-09-22 12:36:22.758673+0800 eBeePartners[460:61967] [BoringSSL] Function nw_protocol_boringssl_input_finished: line 1389 Peer disconnected during the middle of a handshake. Sending errSSLFatalAlert(-9802) alert
2017-09-22 12:36:22.813732+0800 eBeePartners[460:61967] TIC TCP Conn Failed [2:0x1c0166900]: 3:-9802 Err(-9802)
2017-09-22 12:36:22.848609+0800 eBeePartners[460:61719] [MC] Lazy loading NSBundle MobileCoreServices.framework
2017-09-22 12:36:22.854700+0800 eBeePartners[460:61719] [MC] Loaded MobileCoreServices.framework
2017-09-22 12:36:22.864960+0800 eBeePartners[460:61719] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-09-22 12:36:22.898137+0800 eBeePartners[460:62011] *** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIFoundation/UIFoundation-543/UIFoundation/TextSystem/NSLayoutManager_Private.m:1619
2017-09-22 12:36:23.117424+0800 eBeePartners[460:62011] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
*** First throw call stack:
(0x18217fd38 0x181694528 0x18217fc0c 0x182b0ec90 0x18c65a70c 0x18c65a194 0x18c689e4c 0x18c689b08 0x18c6b3f88 0x18b8ebf28 0x18b5b1218 0x18c1e697c 0x18b6613ec 0x1025c8274 0x1025a8360 0x1025a7e90 0x1025a838c 0x1025a6a3c 0x1025c5920 0x1043e545c 0x1043e617c 0x10259c4cc 0x10259c46c 0x100c9ef7c 0x100bd18c0 0x1043e549c 0x1043e545c 0x1043f6cd8 0x1043f6880 0x181dab130 0x181daac30)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

How to debug this code?

I also had this error ONLY AFTER upgrading to Xcode9/Swift4. As mentioned in comments, the reason is calling ui-operations in background thread. I don't know why it has been working until upgrading.

How to debug

You are seeing this error on Xcode which process frozen by debugger, right? Then, the left side panel (called "debug navigator") is showing call stack and indicating the line where the app crashed. You can click one of them and get the code.

In my case

The cause of error is performSegue attempted to run on the main thread in my case.

func downloadHandler() {
    DispatchQueue.global(qos: .default).async(execute: {

        DispatchQueue.main.async(execute: {
            self.labelMessage.text = "Unzipping downloaded data..."
        })

        /* Unzipping something... */

        // WRONG: This causes error
        // self.performSegue(withIdentifier: "toViewController", sender: nil)

        // FIXED: performSegue should be run on main thread.
        DispatchQueue.main.async(execute: {
            self.performSegue(withIdentifier: "toViewController", sender: nil)
        })
    })
}

Double check your DispatchQueue . It would be better to start at where debugger stopped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM