App crashes after displaying a ModalViewController and going to background state - ios

My iOS app keeps crashing. I found the way I could make it crash consistently. I repeated the operation multiple times and I get the same crash log every single time.
The crash happens if I do the following: launch the app, use it a bit (optional), go to the main screen, open a modal ViewController, dismiss it, keep using the app (optional), close the app (press home button, not kill the app), wait a bit (optional), re-open the app. When the app is re-opened, it crashes after 1 second. Note that where you are in the app when you leave it does not cause/prevent the crash. No matter where you are on the app, it crashes the same way. If I use the app and don't open the modal VC, I can send it in background and re-open it with no problem.
Here is some of the crash log I get every time (I took out what I thought was not related, I can provide the full log):
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x317d332c __pthread_kill + 8
1 libsystem_c.dylib 0x33ed0208 pthread_kill + 48
2 libsystem_c.dylib 0x33ec9298 abort + 88
3 libc++abi.dylib 0x36d56f64 abort_message + 40
4 libc++abi.dylib 0x36d54346 _ZL17default_terminatev + 18
5 libobjc.A.dylib 0x35321350 _objc_terminate + 140
6 libc++abi.dylib 0x36d543be _ZL19safe_handler_callerPFvvE + 70
7 libc++abi.dylib 0x36d5444a std::terminate() + 14
8 libc++abi.dylib 0x36d5581e __cxa_rethrow + 82
9 libobjc.A.dylib 0x353212a2 objc_exception_rethrow + 6
10 CoreFoundation 0x37572506 CFRunLoopRunSpecific + 398
11 CoreFoundation 0x37572366 CFRunLoopRunInMode + 98
12 GraphicsServices 0x33d31432 GSEventRunModal + 130
13 UIKit 0x3131ecce UIApplicationMain + 1074
14 ***my app name** 0x0006f140 0x6b000 + 16704
15 ***my app name** 0x0006d5f0 0x6b000 + 9712
It's hard to provide some code, and I don't even know what I could possibly give..
I'd love some help, I have no idea why this is happening..

Feels to me like some cleanup is happening whilst you're in the background. If it's not iOS 6 then check what you;re doing to handle viewDidUnload and in any version, check what you're doing in viewWillDisappear/viewDidDisappear and viewWillAppear/viewDidAppear.

Related

IOS App crashes in Release build but not in debug : IN-app purchase

As I said in the title, I am writing an app for iPhone which runs perfectly in debug mode but when I build it as release and install it via TestFlight, it crashes at the first page
At my first page, it loads my in-app purchase record via cloud functions instead of raw api calling.
Would you please tell me how to obtain the logs from the release version of the app or testing the app via XCode which is under release mode ?
When I catch the crash log , that gives the following ;
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 bookledge 0x0000000104425398 0x1043f0000 + 218008
1 bookledge 0x000000010447f7b0 0x1043f0000 + 587696
2 libdispatch.dylib 0x00000001e8130a38 _dispatch_call_block_and_release + 24
3 libdispatch.dylib 0x00000001e81317d4 _dispatch_client_callout + 16
4 libdispatch.dylib 0x00000001e81119e4 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 1008
5 CoreFoundation 0x00000001e868432c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
6 CoreFoundation 0x00000001e867f264 __CFRunLoopRun + 1924
7 CoreFoundation 0x00000001e867e7c0 CFRunLoopRunSpecific + 436
8 GraphicsServices 0x00000001ea87f79c GSEventRunModal + 104
9 UIKitCore 0x000000021514fc38 UIApplicationMain + 212
10 bookledge 0x00000001043f7704 0x1043f0000 + 30468
11 libdyld.dylib 0x00000001e81428e0 start + 4
Extra: At the beginning, I create onBoard storyboard to put Main storyboard. Default starting point is Main. Given I have forced to turn users to redirect on OnBoard storyboard, somehow the view controller of the first page begins and calls viewDidLoad and viewWillAppear. When I finish scrolling to the end of the onBoard page and press the button, then ,
the first page begins and calls viewDidLoad and viewWillAppear again. Does this occurrence contribute to the crash log above?

How to find root cause Crashed: com.apple.main-thread in production app?

i have such a report from Crashlytics:
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x000000019503fbd0 objc_msgSend + 16
1 CoreFoundation 0x00000001836e5458 CFRelease + 524
2 CoreFoundation 0x00000001836f1a18 -[__NSArrayM dealloc] + 152
3 libobjc.A.dylib 0x0000000195045724 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 564
4 CoreFoundation 0x00000001836e9074 _CFAutoreleasePoolPop + 28
5 Foundation 0x000000018461a588 -[NSAutoreleasePool release] + 148
6 UIKit 0x00000001882b4460 -[UIApplication _run] + 588
7 UIKit 0x00000001882aefac UIApplicationMain + 1488
Is there anything I can do to catch such an issue? It happens on customer devices so I have no chance to reproduce it.
For crashes like this one, if the crash is reproducible, turn on NSZombies in your project's environment variables. This will keep deallocated objects alive (zombies) and when one of them is messaged, the caller and message will be captured on the crashing object.
Turn it off when done as it can block the memory of the app due to the objects not being released for zombie tracking.
Some of logic code need to be run in background. You need to try debug where is code is error and then add this code
DispatchQueue.main.async(execute: {
// your code
})
It's been answered here: objc_msgSend [__NSArrayM dealloc] crash report sometimes from Crashlytics
Basically, upgrade your Crashlytics framework to past 3.0.9. The crash was in the crash reporting framework itself.

weird crash when launching app from Notification Center

I'm at my wits end, I'm getting a weird crash that only happens when the app is launched from Notification Center. Either tapping on a local notification (in the notification side) or a call to extensionContext:openURL:completionHandler (from my Today widget) will launch the app with a customURL scheme.
When the app is running (warm boot), no issues, works just as advertised. When I kill the app (in task switcher) and then try to launch it through Notification Center (cold boot), I get the below crash report.
I've search low and high for anything, can't find it. This only happens on iOS8 devices, iOS7 devices has no issue (with the notification launch, obviously no Today widget)
Has anyone seen this??
thanks!
Date/Time: 2014-10-14 18:16:39.924 -0400
Launch Time: 2014-10-14 18:16:38.667 -0400
OS Version: iOS 8.0.2 (12A405)
Report Version: 105
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000016a4cbeb8
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000000195ebbbd0 objc_msgSend + 16
1 UIKit 0x000000018a27d840 -[UIApplication workspaceDidEndTransaction:] + 216
2 FrontBoardServices 0x000000018da7563c __31-[FBSSerialQueue performAsync:]_block_invoke + 24
3 CoreFoundation 0x000000018582a35c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
4 CoreFoundation 0x0000000185829464 __CFRunLoopDoBlocks + 308
5 CoreFoundation 0x0000000185827a88 __CFRunLoopRun + 1752
6 CoreFoundation 0x0000000185755660 CFRunLoopRunSpecific + 392
7 UIKit 0x000000018a05f4fc -[UIApplication _run] + 548
8 UIKit 0x000000018a05a4f4 UIApplicationMain + 1484
9 therichest 0x00000001001caa8c main (main.m:16)
10 libdyld.dylib 0x0000000196516a04 start + 0
Either your code or a third-party library you are using is manually spinning the runloop. This is causing -workspaceDidEndTransaction: to be called re-entrantly and triggers a use after free. If you set a breakpoint on -[NSRunLoop runMode:beforeDate:] and -[NSRunLoop runUntilDate:], it should hit with the guilty code being on the previous stack frame.
While manually spinning the run loop is never recommended, if you can delay doing it until your application finishes starting up (all the launch app delegate calls received) you should avoid hitting this crash.

AFNetworking crash analysis for EXC_BAD_ACCESS KERN_INVALID_ADDRESS

I'm getting crash reports of AFNetworking throwing an EXC_BAD_ACCESS KERN_INVALID_ADDRESS:
Thread : Crashed: com.apple.root.default-priority
0 libobjc.A.dylib 0x39e237fa objc_release + 9
1 MY_APP 0x0015ba63 __64-[AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke (AFHTTPRequestOperation.m:266)
2 MY_APP 0x00163bf7 __47-[AFURLConnectionOperation setCompletionBlock:]_block_invoke (AFURLConnectionOperation.m:301)
3 Foundation 0x3049a2a9 __103+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke96 + 12
4 libdispatch.dylib 0x3a30b0c3 _dispatch_call_block_and_release + 10
5 libdispatch.dylib 0x3a3107d9 _dispatch_root_queue_drain + 224
6 libdispatch.dylib 0x3a3109c5 _dispatch_worker_thread2 + 56
7 libsystem_pthread.dylib 0x3a43adff _pthread_wqthread + 298
I need help to understand the possible bug. This is something that happens sometimes, actually is very rare and it could be related to a timeout issue when user is using 3G (network can be disconnected while loading data).
I don't post my code because I can't find on the crash log in which file or class this crash happened and I use AFNetworking in a lot of files.
Without any code this is all conjecture but:
Something in the completion block is being accessed after it is deallocated. Commonly, this happens when a network operation isn't cancelled after a view controller is dismissed.

iOS: How should I read this crash report that says my app was killed via pthread_kill and SIGABRT?

I am wondering if there is anything in the following stack trace that I received from Crashlytics that I should be concerned about:
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x000000007becbeb8
Thread : Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0x3a3c61fc __pthread_kill + 8
1 libsystem_pthread.dylib 0x3a42fa33 pthread_kill + 58
2 libsystem_c.dylib 0x3a376ffd abort + 76
3 libc++abi.dylib 0x396a5cd7 abort_message + 74
4 libc++abi.dylib 0x396be6e5 default_terminate_handler() + 252
5 libobjc.A.dylib 0x39e07921 _objc_terminate() + 192
6 libc++abi.dylib 0x396bc1c7 std::__terminate(void (*)()) + 78
7 libc++abi.dylib 0x396bbd2d __cxa_increment_exception_refcount
8 libobjc.A.dylib 0x39e077f7 objc_exception_rethrow + 42
9 CoreFoundation 0x2f499c9d CFRunLoopRunSpecific + 640
10 CoreFoundation 0x2f499a0b CFRunLoopRunInMode + 106
11 GraphicsServices 0x3419a283 GSEventRunModal + 138
12 UIKit 0x31d3d049 UIApplicationMain + 1136
13 Pocket Linesman 0x0005aa8b main + 17 (main.m:17)
From my searching around the internet, I am unable to find an example of where this type of crash has an actionable fix for it. Also, I am completely unable to reproduce a crash like this through a normal interaction in my app.
Does this stack trace indicate a normal crash due to low memory issues on the user's iOS device, or something more?
This is my first app using Crashlytics, so i am still learning how to read the reports it sends me.
Thanks!
The original source of the crash is an uncaught exception. The original exception was caught and rethrown from CFRunLoopRunSpecific(). That has obscured the original source of the exception in the backtrace. Sometimes, the exception details are logged and they might indicate the original backtrace. Do you have any log messages that may have been written at the same time?
I was running into the same issue whenever the crash was caused by UI code.
Have you set NSSetUncaughtExceptionHandler in your app delegate by any chance? Setting mine caused me to get the useless pthread_kill message.
Unsetting mine in distributed builds allowed me to get more useful crash reporting from the same error.
Hope this helps :)

Resources