Generating crash reports on Cocoa Touch apps - ios

That probably sounds a lot worse than it is, but here's my question.
I am dealing with a crash on an actual device, that one of my tester's is using. At the moment, there is no way to discover what is causing the crash. I can not reproduce it on the simulator. However, on the simulator when something crashes I get log info about it in the output window. But I don't want to keep testing with the device connected.
Is it possible to log crash exceptions, etc into a file when things crash. I know certain apps can do it, but I am not sure how?
Any info would be appreciated.

There are generally two ways to do that:
Someone get the tester to send you the crash reports, that iOS created on the device. This is usually too tricky for end users, so the next suggestion works better. That's also why I am not describing how to do that :) But you'll find plenty of documentations on that process.
Integrate a crash reporting library, that catches the crashes and allows you to receive them in various ways. You should not implement your own global crash exception handler, things are just too complex to do it right (even though other people will tell you otherwise). Also crashes caused by exceptions are only one type of crashes.
There are multiple open source libraries out there, the safest one to use is anything based on PLCrashReporter. Most others use private or undocumented iOS APIs, or are not async-safe, which basically means those can destroy app data or make the crash even worse. See this blog post about the topic: http://landonf.bikemonkey.org/code/crashreporting/Reliable_Crash_Reporting_1.1.20130119.html
The following linked answer shows some of the available options on how to add logging to your app and also various options on how to receive crash reports for test version and also once the app is released: Including custom data into iOS crash dumps

If you're open to using a third party service, I use https://www.crashlytics.com. Makes debugging crashes from user devices painless.

Related

Identify Crash log in iOS

We have used several 3rd party crash logs in past like crittercism, Flurry, crashlytics etc. There're some crash logs in which we are not able to get exact crash point. So, do we have any tool available which provides exact crash point ?
OR which is best 3rd party crash log tools in iOS ?
Depending on the type of crash, stack traces may not contain any of your apps code, which is perfectly fine.
Especially when dealing with memory issues, the crash will happen somewhere completely different than where the bug in your application is. You will have to check for the Exception Type information in the crash log and then go from there.
The following documents can help you understand crash reports better:
https://developer.apple.com/library/ios/technotes/tn2151/_index.html
http://www.raywenderlich.com/23704/demystifying-ios-application-crash-logs
You should also use the tools Xcode provides to make sure there are no easy to detect bugs by using the Instruments Leaks tool, use the Analyze build feature in Xcode, or the Address Sanitizer check in Xcode 7.

How to debug a crash that occurs randomly in an iOS application?

Currently, I am using Crittercism for crash reporting and making sure that I add dSYMs to get symbolicated crash reports.
But it is not helping with some of my crashes which are segmentation faults (SIGSEGV and SIGBUS). They occur randomly and I haven't been able to reproduce them on device and on simulator. I have tried to find a pattern by trying my app on different ios devices with different network connections (3G, Wifi, Edge) but with no success.
What can be my next step?
Not much to go on, but here are a few places to look:
If you have multiple threads, check to make sure they are behaving properly. Make sure you synchronize properly if multiple threads could be accessing the same objects.
Check your NSNotifications - could one be posted when you are not expecting it?
I have found that the hardest bugs to find are those that are caused by asynchronous events - either in other threads or due to external events that you might be monitoring.
Not being able to reproduce the bug in your development environment will make it very hard to find.

Diagnosing non-reproduceable bugs?

I've got a very basic, but terribly important and potentially impossible question: how does one go about diagnosing a bug you can't reproduce?
Twice now, I've gotten emails from people asking about app-crashing bugs that I can't reproduce. Non-modified iPhones, current software, tried reinstalling and hard resets, etc. It crashes every time for them, and it works perfectly for me, (not to mention it got approved for the App Store in the first place so I'm clearly not the only one). I had always understood that the consistency of the devices was one of Apple's big selling points for developers, but that also makes it hard to pinpoint what's different about their device from mine...
So, aside from "just keep testing," is there a trick-of-the-trade among programmers for this sort of thing? Some function of the iPhone simulator that lets you test not just different screen sizes but different hardware configurations, etc? Or am I just out of luck, and stuck telling my customer "sorry, it works for me"?
Can anyone share their experiences or suggestions about this?
You should probably start by installing a crash reporting tool like Crashlytics. This may give you the clues you need or at least help you narrow down where to put additional crash logging.
While the iTunes Connect crash reports can be helpful, the crash reporting services like Crittercism are more user-friendly and full-featured. Crittercism has been very helpful in tracking down infrequently-occurring crashes for my apps and can be used no-charge. (I have no association with Crittercism.)
In iTunes Connect you can access crash reports. These crash reports include call stacks that you can symbolicate and then you can see where it actually crashes.
Here is some good instructions for symbolicating: symbolicating-iphone-app-crash-reports
It's important to keep your dsym files from each build & archive safe. You can use them to symbolicate crash reports, to see details of the crash. Users will have to opt in to submitting crash reports though. I think this is a feature of iTunesConnect.

Is there a way to have our own app to upload its crash repot?

Not sure if that is possible. But what happens is, sometimes our app randomly crashes. We don't know what exactly the problem is. Is there a way for us to get the crash report off user's iphone? By code, or by another app?
Thanks.
You can inject a third party code in your app, which would basically save your crash reports and thereafter you can use them for analysis. The way we do is capture any crash logs and upload them to the app server, which uses the info to display through a user-friendly web Interface (access controlled for admin purposes).
A great open source Crash Reporter library can be found here https://github.com/kstenerud/KSCrash
It's the user who decides from Settings > General > About > Diagnostics & Usage whether to automatically send crash reports or not.
You can also use a third party component to get detailed information about crash events, for example Crittercism.
If you're interested in 3rd party services for crash reporting for iOS it's hard to go past Crashlytics. Very fast crash reporting, simple installation, great response times to queries.
I'd also mention the TestFlight SDK, which is free and easy to use, and allows you to gather crash reports easily from all your testers, and also do remote logging and other stuff. I used it on a location based app I was working on a while ago, and it was very helpful with debugging

Including custom data into iOS crash dumps

Hello Stack Overflow !
A simple question for you : is it possible to embed custom error data into automatically generated iOS crash dumps I get from my users when my app crashed on their device ?
For example : My SQlite database won't operate for some reason (say, the database file is corrupted).. I cannot recover from this error, so I throw an exception, and embed in the exception the detailed sqlite error message. The problem is, the crash dump of the application won't contain the exception message, so it's not easy to know under which conditions the application crashed.
Does anyone know a way to put things into the crash dump report ? Or do you have any other recommended way of reporting production crashes to the developper ?
Thanks !
No, you cannot ad your own data into the crash reports. It is also not possible to access iOS generated crash reports automatically because of the sandbox.
So my suggestion is as follows:
For logging your own data, use Cocoalumberjack. It is much faster than NSLog or other logging frameworks out there and has an option to log your messages into a file. Now when an exception occurs, or whenever else you want to, log that into a file. But if your app crashes right at a point where you add something into a log file, it most likely will be missing, since the app crashed the very same moment.
So its rather impossible to safely catch the exact SQL statement. But the crash report should give you enough information to understand what is happening, with the addition to what you logged of being done before. E.g. you could log the search string used in the SQL way before the SQL is being executed.
In general try not to log too much.
For catching crash report you should nothing else than a solution based on the open source framework PLCrashReporter, which can safely catch crashes, also when you app is already in the app store! Exception catching is not recommended, check this article to see why!
iTunes Connect offers you to view some crash reports too, but it takes up to 2 weeks to see some, but by far not all as e.g. pointed out by the Camera+ developers. So you better use your own solution.
PLCrashReporter will send you standard apple formatted crash reports, ready for symbolication, so you know where the crash happens in your code, including line numbers.
Some solutions based on PLCrashReporter are:
QuincyKit: Open Source client + php server, basic crash grouping, symbolication can be automated from your mac (I am the developer of this)
HockeyApp: Paid service, uses QuincyKit client, advanced crash grouping, symbolication fully done on the server (I am on of the developers of this)
Bugsense: Free service, symbolication announced as premium feature
AppBlade: Paid service, symbolication unknown
Crashlytics: Private beta, unknown features, their solution seems to be based on PLCrashReporter
The proposed solutions either allow sending the data automatically on the next startup or by asking the user if he/she agrees to send.
Disclaimer-as-per-the-faq: I am a developer for AppBlade.
AppBlade allows you to send custom parameters along with symbolicated crash reports as of December 2012.
Check it out! http://blog.appblade.com/news/2012/12/appblade-sdk-update-sessions-and-queues/

Resources