Main Thread Checker: UI API called on a background thread iOS 11 Xcode 9 GM Seed - objective-c

Can anyone please help me in debugging this issue, from the time i started working with Xcode 9 GM seed with iOS 11 GM seed, my code throwing me a warning in the console saying:
2017-09-18 16:22:52.872716+0530 **** *****[359:20158] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication
applicationState] .PID: 359, TID: 20158,
Thread name: Runtime Network Callback Thread,
Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
also, i'm using ESRI maps in my application, when ever i zoom in or zoom out in ESRI maps i'm getting this error:
2017-09-18 16:22:53.176524+0530 *** ***[359:20063] Task <5F9376DB-9335-
4A45-B3F0-1D6FD69A19A3>.<29> finished with error - code: -999
2017-09-18 16:22:53.178923+0530 *** ***[359:20142] Task <0DE282EA-3FBD-
4036-8298-C75EFA65F15A>.<40> HTTP load failed (error code: -999 [1:89])
2017-09-18 16:22:53.179821+0530 *** *[359:20063] Task <BE2D8BAE-FFB8-
43CA-8723-111326DEF4FD>.<31> finished with error - code: -999
2017-09-18 16:22:53.180089+0530 *** ***[359:20063] Task <E7C819D4-C11A-
4915-B021-A73F31BE89CD>.<33> finished with error - code: -999
2017-09-18 16:22:53.180365+0530 *** ***[359:20063] Task <3B871761-B006-
4220-B857-6204B385AD34>.<34> finished with error - code: -999
2017-09-18 16:22:53.180523+0530 *** ***[359:20142] Failed to get
TCPIOConnection in addInputHandler.
Application works fine with Xcode 8 iOS 10.3.3. Problem seems to be with Xcode 9. Can anyone please help me in debugging this issue. Thanks

Xcode 9 adds a new runtime checks which is the Main Thread Checker.
According to Apple documentation:
The Main Thread Checker is a standalone tool for Swift and C languages
that detects invalid usage of AppKit, UIKit, and other APIs on a
background thread. Updating UI on a thread other than the main thread
is a common mistake that can result in missed UI updates, visual
defects, data corruptions, and crashes.
You already had this issue in your app with Xcode 8. It's just that the tool to detect it was not there yet.
In your case, it seems that it's a call to UIApplication.shared.applicationState that is causing this runtime issue.
You can configure your app scheme to stop execution when it happens. It is a checkbox in the Diagnostics tab, under the Main Thread Checker section.

Related

Crash in the execution of a queue glmtl.telemetry

Exactly 60 seconds after launching my app it crashes with an uncaught exception:
libc++abi.dynlib: terminating app due to uncaught exception of type NSException
*** Terminating app due to uncaught exception of type 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: BundleVersion)'
The crashing thread has a random number (it is #7 in the attached screenshot) and it is always created for an unknown to me queue glmtl.telemetry.
The crash occurs only on one device (iPhone 11 Pro Max) and iOS 14.0 (it was then replicated with iOS 14.0.1).
I am not using in the project anywhere a key "BundleVersion". (There is CFBundleVersion in the info.plist, but does not seem to be related).
Can this be caused by the project sources?
This is not an explanation of the issue but the crash stopped appearing after adding a group of missing resource files to a folder (not a group but a folder) in the bundle.
Fix
I am having the same issue. In my case, I needed to add CFBundleVersion to the project's Info.plist since the exception mentions the "BundleVersion" key and because I recalled seeing XCode complain about invalid bundles when that key is missing.
My guess is that those recommended CFBundle* keys should be set for the main project's Info.plist and any embedded framework or projects with their own Info.plist. I'm just surprised XCode 12 doesn't raise that error right now at build time.
Source of the issue (?)
Do you use OpenGL in your app? I could not find what glmtl is, but it seems that the crash occurs exactly 1 minute after I instantiate a new OpenGL context. The crash will still occur after 1 minute if I delete the context before that, but it will be delayed another minute if I create a new instance in between.

Crash when using Voiceover

Crash only when using Voiceover, good performance when shutting down
This only happens on XCode 11 and iOS 13
void SendDelegateMessage(NSInvocation *): delegate (webView:resource:didFinishLoadingFromDataSource:) failed to return after waiting 10.000000 seconds. main run loop mode: kCFRunLoopDefaultMode
nw_connection_receive_internal_block_invoke [C26] Receive reply failed with error "Operation canceled"
Message from debugger: Terminated due to memory issue
This is the last content that appears in the console, then the program crashes
I also experience a crash with both iOS 13.0 and 13.1, but with Voice Control, not VoiceOver.
For some reason, if you launch the application after Voice Control being enabled, viewDidLoad() is called right after you assign rootViewController to a window.
Normally it is called (if Voice Control disabled and at previous iOS version) from main, not after rootViewController assign.
I solved mine crash using rather a hack than a real solution like this:
let root = YourUIViewController()
This will crash on iOS 13 if Voice Control is enabled
window?.rootViewController = UINavigationController(rootViewController: root)
This will not crash on iOS 13 with enabled Voice Control
let mainWindow = UIWindow()
mainWindow.rootViewController = UINavigationController(rootViewController: root)
window = mainWindow
Looks like an iOS 13.1 bug for me. But I'm not sure if it actually is a bug or a new feature.
Also I've described my issue more detailed here

How do I get XCode to break on all console / log messages?

I have a message from it seems Core Foundation printing into the debug console in XCode (OS X app), "CGContextGetCompositeOperation: invalid context 0x0. This is a serious error....".
I don't know where in my app this line is being generated. (big app)
I tried breaking on NSLog(), CFLog() syslog(), printf(), fprintf, and none of those breakpoints stop on that output. All of those breakpoints work if I test them, etc.
Is there a symbol I can break on that will stop every time a message is printed to the console?
Or is there some function that Apple uses that I can break on?

My app freezes and I don't know what's wrong

So, my app works perfectly except that it freezes after a while of using it in the simulator. Any ideas?
The following error occurs:
App Game[6352:60b] *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:], /SourceCache/UIKit/UIKit-2935.137/UIWindowController.m:223
2014-04-18 11:32:43.237 App Game[6352:60b] *** WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame: delegate: <NSInternalInconsistencyException> Attempting to begin a modal transition from <ViewController: 0x15f625180> to <GADWebAppViewController: 0x15f53e5d0> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed
2014-04-18 11:32:49.603 App Game[6352:60b] Warning: Attempt to present <Game: 0x15f659030> on <ViewController: 0x15f625180> while a presentation is in progress!
Just dealt with this problem. I was using the SimpleAuth to authenticate Instagram for an app, and found out that I was calling the SimpleAuth authorize method twice. The second call was causing this error by trying to present it's own modal before the first call had dismissed it's own.

Xcode crashes - but only for a specific project (target 'MyApp' has been asked for its build context but it does not belong to a project)

Whenever I try to run a specific project / app from Xcode it crashes with the details in the backtrace (please see below).
All sorts of funny stuff is going on running this in Xcode.
First, deleting the app from the iPad simulator and then running it for the first time seems to be working 90% of the time. But then either the second or the third attempt running on the iPad simulator it crashes again.
Trying to run it on a iPad device always crash, not luck at all.
Another funny thing I noticed is that whenever I do manage to get it to run for a second time on the iPad simulator all my appearance code (colors etc.) define in my app delegate is gone...
The only clue I could gather from the backtrace is: target 'MyApp' has been asked for its build context but it does not belong to a project
So, I'm not sure wheter this is Xcode related or perhaps somthing with the workspace / project file since it only crashes on this very specific project. If it is a problem with my workspace or project file, does anybody know how to fix this?
I appreciate your help.
Backtrace details:
Application Specific Information:
ProductBuildVersion: 4E2002
ASSERTION FAILURE in /SourceCache/IDEXcode3ProjectSupport/IDEXcode3ProjectSupport- 1197/Xcode3Sources/XcodeIDE/Frameworks/DevToolsBase/pbxcore/Target.subproj/PBXTarget.m:4006
Details: target 'MyApp' has been asked for its build context but it does not belong to a project
Object: <PBXNativeTarget: 0x409f3d8c0>
Method: -targetBuildContext
Thread: <NSThread: 0x40a7d8a80>{name = (null), num = 51}
Hints: None
Backtrace:
0 0x000000010bbbbb9f -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
1 0x000000010b070635 _DVTAssertionFailureHandler (in DVTFoundation)
2 0x000000010e18c505 -[PBXTarget targetBuildContext] (in DevToolsCore)
3 0x000000010e18fec4 -[PBXTarget(XCBuildables) buildDidFinishWithBuildLogRecorder:] (in DevToolsCore)
4 0x000000010e2fefe2 -[Xcode3TargetBuildableSnapshot buildForBuilderDidFinish:] (in DevToolsCore)
5 0x000000010b6bb668 -[IDEBuildableSnapshot performBuildForBuilder:buildCommand:buildOnlyTheseFiles:] (in IDEFoundation)
6 0x000000010b6bada6 -[IDEBuilder main] (in IDEFoundation)
7 0x00007fff95e8b6b4 -[__NSOperationInternal start] (in Foundation)
8 0x00007fff95e9e912 ____NSOQSchedule_block_invoke_2 (in Foundation)
9 0x00007fff96d6da86 _dispatch_call_block_and_release (in libdispatch.dylib)
10 0x00007fff96d6e965 _dispatch_worker_thread2 (in libdispatch.dylib)
11 0x00007fff8f67c3da _pthread_wqthread (in libsystem_c.dylib)
12 0x00007fff8f67db85 start_wqthread (in libsystem_c.dylib)
objc[31243]: garbage collection is ON
abort() called
So I finally figured out what the problem was.
I was using a build script that bumped my build number (CFBundleShortVersionString) after each build.
It seems Xcode doesn't like the fact that the plist file gets changed underneath it.
The only "workaround" I could come up with was to remove the build step containing my version bump script that changed that plist file on every build.
Have faced with that about hour and I haven't auto-increasing build number script. If you are trying to delete target by right-click make sure that this target is closed, even at tab where you are deleting. Select another one and right-click to delete needed target.
Hope it helps