除了crittercism以外,以自己的方式处理iOS例外



我有一个iOS应用程序,我已经在使用Crittercism。它完美地报告了例外。

我的问题是我还希望将这些例外登录到我的后端服务器。

我尝试了很多事情来实现它,但无济于事。这是我尝试过的事情列表:

  • 致电 NSSetUncaughtExceptionHandler(&myExceptionHandler);

如果这样做,则不会在Crittercism中报告例外。

  • 致电 NSSetUncaughtExceptionHandler(&myExceptionHandler);

将异常发送给我的服务器。然后在myExceptionHandler函数中调用Crittercism的构造函数,然后重新恢复例外。不起作用。

  • 呼叫Crittercism的构造函数,其次是NSSetUncaughtExceptionHandler(&myExceptionHandler);,在myExceptionHandler中调用[Crittercism logHandledException:exception];。也不起作用。

  • 在我的异常处理程序中序列化异常对象并将其存储在用户首选项中。当用户重新启动应用程序时,请致电[Crittercism logHandledException:exception];,然后将异常发送到我的后端服务器。问题的问题是,我无法将字符串划分为异常对象。我无法将堆栈跟踪以NSString形式放在我的异常对象中。

我可以尝试的一些事情:

  • 让Crittercism处理异常,然后在下一个重新启动时,crittercismDidCrashOnLastLoad将被调用 - 但是我有例外信息,还是可以从某个地方访问。

  • 我可能不需要将字符串列为异常对象。我相信Crittercism也将例外变成了JSON对象,并将此JSON对象发送到其服务器。但是我无法找出将自定义JSON对象发送到Crittercism的功能。

有人可以指导我如何继续吗?

我找到了解决方案。首先使用

启动crittercism对象
[Crittercism initWithAppID:crittercismAppID andKey:crittercismKey andSecret:crittercismSecret];

现在定义

NSUncaughtExceptionHandler* crittercismHandler = NSGetUncaughtExceptionHandler();//You have stored the reference to the crittercism function that was going to get called in the event of an exception

然后,

NSSetUncaughtExceptionHandler(&myHandledException);//Set the handler to your custom function

在您的自定义功能中,请执行您想做的任何事情,然后致电

NSSetUncaughtExceptionHandler(crittercismHandler);//this will re-set the exception handler to the one of crittercism

呼叫

crittercismHandler(exception);//This will send the exception to crittercism servers.

您可以为信号做类似的事情。

您可以像我们一样管理自己的异常处理。此页面具有指向示例项目的链接http://www.cocoawithlove.com/2010/05/handling-unhandled-exceptions-and-.html

这也很有帮助从另一个线程打印堆栈跟踪

最新更新