2012-10-17 137 views
3

我有一个ios应用程序,我已经在使用Crittercism。它完美地报告了例外情况。处理iOS Exceptions除了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。

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

回答

2

我已经找到了解决这个。首先初始化使用

[Crittercism initWithAppID:crittercismAppID andKey:crittercismKey andSecret:crittercismSecret]; 

的crittercism对象现在定义

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. 

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

相关问题