把这个放在AppDelegate.cs
:
[DllImport ("libc")]
private static extern int sigaction (Signal sig, IntPtr act, IntPtr oact);
enum Signal {
SIGBUS = 10,
SIGSEGV = 11
}
static void EnableCrashReporting ()
{
IntPtr sigbus = Marshal.AllocHGlobal (512);
IntPtr sigsegv = Marshal.AllocHGlobal (512);
// Store Mono SIGSEGV and SIGBUS handlers
sigaction (Signal.SIGBUS, IntPtr.Zero, sigbus);
sigaction (Signal.SIGSEGV, IntPtr.Zero, sigsegv);
// Enable crash reporting libraries
EnableCrashReportingUnsafe ();
// Restore Mono SIGSEGV and SIGBUS handlers
sigaction (Signal.SIGBUS, sigbus, IntPtr.Zero);
sigaction (Signal.SIGSEGV, sigsegv, IntPtr.Zero);
Marshal.FreeHGlobal (sigbus);
Marshal.FreeHGlobal (sigsegv);
}
static void EnableCrashReportingUnsafe ()
{
// Run your crash reporting library initialization code here--
// this example uses HockeyApp but it should work well
// with TestFlight or other libraries.
// Verify in documentation that your library of choice
// installs its sigaction hooks before leaving this method.
var manager = BITHockeyManager.SharedHockeyManager;
manager.Configure (HockeyAppId, null);
manager.StartManager ();
}
EnableCrashReporting ()
在方法的开头调用FinishedLaunching
。如果需要,请
将此调用包装在指令中。#if !DEBUG
它是如何工作的?
我听从了 Rolf 的建议:
一种可能的解决方案是允许 mono 处理所有 SIGSEGV 信号(从技术上讲,崩溃报告库不应该处理 SIGSEGV 信号,或者它应该链接到 mono 的处理程序而不自己做任何处理)。如果 mono 确定 SIGSEGV 信号不是来自托管代码(即发生了非常糟糕的事情),它将引发 SIGABORT 信号(崩溃报告库应该已经处理并视为崩溃)。正如您所理解的,这是必须在崩溃报告库中完成的事情。
和Landon Fuller的 Objective C 实现:
#import <signal.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/* Save Mono's signal handler actions */
struct sigaction sigbus_action, sigsegv_action;
sigaction(SIGBUS, NULL, &sigbus_action);
sigaction(SIGSEGV, NULL, &sigsegv_action);
// Enable the crash reporter here. Ie, [[PLCrashReporter sharedReporter] enableCrashReporterAndReturnError:],
// or whatever is the correct initialization mechanism for the crash reporting service you're using
/* Restore Mono's signal handlers */
sigaction(SIGBUS, &sigbus_action, NULL);
sigaction(SIGSEGV, &sigsegv_action, NULL);
return YES;
}
我使用Banshee 源代码作为如何sigaction
从 MonoTouch 调用的参考点。
希望能帮助到你!