2012-10-17 66 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. 

您可以對信號做類似的事情。

相關問題