There are plenty iOS crash reporting libraries in iOS, including TestFlight and HockeyApp. If you don't want to depend on services, you can still use libraries like PLCrashReporter. Binding these libraries is fairly trivial because their public API usually consists of a couple of classes with several initialization methods.
However, when trying to use TestFlight, and later HockeyApp in our application, our app began to randomly crash. Turns out, this is a known issue reported several times, but Xamarin doesn't warn about it, it is relatively obscure and we found it the hard way.
We have learned that all iOS crash reporters prevent Mono from catching null reference exceptions:
try {
object o = null;
o.GetHashCode ();
} catch {
// Catch block isn't called with crash reporting enabled.
// Instead, the app will crash.
}
Why does this happen? Quoting Rolf, a Xamarin developer,
A null reference exception is actually a SIGSEGV signal at first. Usually the mono runtime handles this and translates it into a nullreference exception, allowing the execution to continue. The problem is that SIGSEGV signals are a very bad thing in ObjC apps (and when it occurs outside of managed code), so any crash reporting solution will report it as a crash (and kill the app) - this happens before MonoTouch gets a chance to handle the SIGSEGV, so there is nothing MonoTouch can do about this.
I'm sure many use TestFlight in MonoTouch apps without knowing it causes crashes.
Isn't it ironic?
How do you make crash reporting libraries not crash MonoTouch apps?
Starting with Xamarin.iOS 10.4 there's now a supported way of doing this:
Put this in
AppDelegate.cs
:Call
EnableCrashReporting ()
in the beginning ofFinishedLaunching
method.Wrap this call in
#if !DEBUG
directive if you want.How does it work?
I followed Rolf's suggestion:
And Landon Fuller's Objective C implementation:
I used Banshee source code as a reference point for how to call
sigaction
from MonoTouch.Hope it helps!