3

我有一个已经在使用 Crittercism 的 ios 应用程序。它完美地报告了异常。

我的问题是我还希望将这些异常记录到我的后端服务器。

我已经尝试了很多事情来实现它,但无济于事。以下是我尝试过的事情的清单:

  • 称呼 NSSetUncaughtExceptionHandler(&myExceptionHandler);

如果我这样做,Crittercism 中不会报告异常。

  • 称呼 NSSetUncaughtExceptionHandler(&myExceptionHandler);

将异常发送到我的服务器。然后在function中调用Crittercism的构造myExceptionHandler函数,重新抛出异常。不工作。

  • NSSetUncaughtExceptionHandler(&myExceptionHandler);myExceptionHandlercall之后调用 Crittercism 的构造函数[Crittercism logHandledException:exception];。也不行。

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

我本可以尝试的一些事情:

  • 让 crittercism 处理异常,然后在下次重新启动时,crittercismDidCrashOnLastLoad将被调用 - 但是我是否有异常信息,或者我可以从某个地方访问它。

  • 我可能不需要将字符串反序列化为异常对象。我相信 Crittercism 还将异常更改为 json 对象并将此 json 对象发送到其服务器。但我无法找出用于将自定义 json 对象发送到 crittercism 的函数。

有人可以指导我如何进行吗?

4

2 回答 2

2

我已经找到了解决方案。首先使用初始化 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.

你可以对信号做类似的事情。

于 2013-02-15T07:09:18.650 回答
1

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

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

于 2012-10-18T01:16:46.743 回答