gpt4 book ai didi

ios - 修改导航栏外观时与 NSAppearance 相关的 NSInternalInconsistencyException

转载 作者:行者123 更新时间:2023-11-28 07:45:27 25 4
gpt4 key购买 nike

我有一个问题。你能告诉我如何解决它吗?感谢请查看崩溃,如果您能找到其背后的原因,请提供帮助。

Fatal Exception: NSInternalInconsistencyException and crashed: com.twitter.crashlytics.ios.exception

Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x184faf164 __exceptionPreprocess
1 libobjc.A.dylib 0x1841f8528 objc_exception_throw
2 CoreFoundation 0x184faf038 +[NSException raise:format:]
3 Foundation 0x1859497f4 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4 UIKit 0x18ee6c3b8 +[NSObject(UIAppearanceAdditions) _installAppearanceSwizzlesForSetter:]
5 UIKit 0x18ee6ed0c -[_UIAppearance _beginListeningForAppearanceEventsForSetter:]
6 UIKit 0x18ee6efb4 -[_UIAppearance _handleSetterInvocation:]
7 CoreFoundation 0x184fb481c ___forwarding___
8 CoreFoundation 0x184e99ccc _CF_forwarding_prep_0
9 MasterProjectAPI 0x102ac0cd4 PivotshareHelper.setUpDesign() -> () (PivotshareHelper.swift:304)
10 MasterProjectAPI 0x102acace8 specialized PivotshareHelper.(getChannel() -> ()).(closure #1) (PivotshareHelper.swift:14)
11 MasterProjectAPI 0x102ae6764 partial apply for PivotshareHelper.(getAuthors() -> ()).(closure #1)
12 MasterProjectAPI 0x102b62b70 Data?URLResponse?Error? (VidappHelper.swift)
13 CFNetwork 0x185539d68 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke
14 CFNetwork 0x1855526bc __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke
15 Foundation 0x185985ba0 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
16 Foundation 0x1858c5894 -[NSBlockOperation main]
17 Foundation 0x1858b54c4 -[__NSOperationInternal _start:]
18 libdispatch.dylib 0x18492ea14 _dispatch_client_callout
19 libdispatch.dylib 0x184936200 _dispatch_block_invoke_direct$VARIANT$mp
20 libdispatch.dylib 0x18492ea14 _dispatch_client_callout
21 libdispatch.dylib 0x184936200 _dispatch_block_invoke_direct$VARIANT$mp
22 libdispatch.dylib 0x1849360ac dispatch_block_perform$VARIANT$mp
23 Foundation 0x185987878 __NSOQSchedule_f
24 libdispatch.dylib 0x18492ea14 _dispatch_client_callout
25 libdispatch.dylib 0x184936f08 _dispatch_continuation_pop$VARIANT$mp
26 libdispatch.dylib 0x18493580c _dispatch_async_redirect_invoke$VARIANT$mp
27 libdispatch.dylib 0x18493bcf4 _dispatch_root_queue_drain
28 libdispatch.dylib 0x18493ba38 _dispatch_worker_thread3
29 libsystem_pthread.dylib 0x184bd706c _pthread_wqthread
30 libsystem_pthread.dylib 0x184bd6b6c start_wqthread`


crashed: com.twitter.crashlytics.ios.exception
0 MasterProjectAPI 0x102ce762c CLSProcessRecordAllThreads (CLSProcess.c:376)
1 MasterProjectAPI 0x102ce762c CLSProcessRecordAllThreads (CLSProcess.c:376)
2 MasterProjectAPI 0x102ce7aa0 CLSProcessRecordAllThreads (CLSProcess.c:407)
3 MasterProjectAPI 0x102cd83b4 CLSHandler (CLSHandler.m:26)
4 MasterProjectAPI 0x102ce5c58 __CLSExceptionRecord_block_invoke (CLSException.mm:199)
5 libdispatch.dylib 0x18492ea14 _dispatch_client_callout + 16
6 libdispatch.dylib 0x184937618 _dispatch_queue_barrier_sync_invoke_and_complete + 56
7 MasterProjectAPI 0x102ce56f4 CLSExceptionRecord (CLSException.mm:206)
8 MasterProjectAPI 0x102ce5524 CLSExceptionRecordNSException (CLSException.mm:102)
9 MasterProjectAPI 0x102ce5134 CLSTerminateHandler() (CLSException.mm:259)
10 libc++abi.dylib 0x1841e854c std::__terminate(void (*)()) + 16
11 libc++abi.dylib 0x1841e85b8 std::terminate() + 60
12 libobjc.A.dylib 0x1841f876c _destroyAltHandlerList + 10
13 libdispatch.dylib 0x18492ea28 _dispatch_client_callout + 36
14 libdispatch.dylib 0x184936200 _dispatch_block_invoke_direct$VARIANT$mp + 288
15 libdispatch.dylib 0x18492ea14 _dispatch_client_callout + 16
16 libdispatch.dylib 0x184936200 _dispatch_block_invoke_direct$VARIANT$mp + 288
17 libdispatch.dylib 0x1849360ac dispatch_block_perform$VARIANT$mp + 104
18 Foundation 0x185987878 __NSOQSchedule_f + 376
19 libdispatch.dylib 0x18492ea14 _dispatch_client_callout + 16
20 libdispatch.dylib 0x184936f08 _dispatch_continuation_pop$VARIANT$mp + 428
21 libdispatch.dylib 0x18493580c _dispatch_async_redirect_invoke$VARIANT$mp + 604
22 libdispatch.dylib 0x18493bcf4 _dispatch_root_queue_drain + 600
23 libdispatch.dylib 0x18493ba38 _dispatch_worker_thread3 + 120
24 libsystem_pthread.dylib 0x184bd706c _pthread_wqthread + 1268
25 libsystem_pthread.dylib 0x184bd6b6c start_wqthread + 4

===> 还有我的代码。是304行

    navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:highLightColour, NSFontAttributeName:font]

更新:我在我的代码中找到了原因。它同时运行两个线程。

示例:

let queue: OperationQueue = OperationQueue()
queue.maxConcurrentOperationCount = 2
queue.addOperation({
let navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.barTintColor = UIColor.red
navigationBarAppearace.tintColor = UIColor.yellow
if let font = UIFont(name: "Lato-Regular", size: 18.0) {
navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.blue, NSFontAttributeName:font]
}

})
queue.addOperation({
let navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.barTintColor = UIColor.red
navigationBarAppearace.tintColor = UIColor.yellow
if let font = UIFont(name: "Lato-Regular", size: 18.0) {
navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.blue, NSFontAttributeName:font]
}
})

但是,我不明白为什么用两个线程运行会出错。你有理由吗?

最佳答案

当与 Apple 的 UI 框架交互时,我们需要确保在主线程中进行调用,因为 iOS 仅在主线程上更新 UI。从多个线程访问单个资源会造成死锁情况。

但是,您应该切换到主队列来更新 UI 相关工作。

    // back to UI thread
OperationQueue.main.addOperation {
let navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.barTintColor = UIColor.red
navigationBarAppearace.tintColor = UIColor.yellow
if let font = UIFont(name: "Lato-Regular", size: 18.0) {
navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.blue, NSFontAttributeName:font]
}
}

您可以阅读这篇文章 Threading on Swift

谢谢!

关于ios - 修改导航栏外观时与 NSAppearance 相关的 NSInternalInconsistencyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51169620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com