我正在使用http://code.google.com/p/google-toolbox-for-mac中的 GTMStackTrace .
我需要一种方法来测试最终用户在应用程序崩溃时向我发送错误.我知道如何将数据发送到我的网站,但问题是如何捕获所有未处理的错误.
我有这个代码:
void exceptionHandler(NSException *exception) {
NSLog(@"%@", [exception reason]);
NSLog(@"%@", [exception userInfo]);
NSLog(@"%@", GTMStackTraceFromException(exception));
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Error unexpected",@"Info: Can't save record")
message:GTMStackTraceFromException(exception) delegate:nil
cancelButtonTitle:NSLocalizedString(@"Ok",@"Button: Ok") otherButtonTitles:nil];
[alert show];
[alert release];
}
int main(int argc, char *argv[]) {
//For crash report..
NSSetUncaughtExceptionHandler(&exceptionHandler);
//Normal code...
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
然而,事情不是抓了很多的错误,像一个坏的版本,一个BAD ACCES等,和App消失.我有2个问题,其中目前尚不清楚为什么happend和最终用户有没有什么要说的线索.
(例如,释放两次相同的var不能捕获)
那么,如何我得到的所有讨厌的错误,从而使最终用户简单的给我发一份崩溃报告吗?
嗨大家我有一个类我想将用户重定向到错误页面,如果它是:未捕获的异常,捕获的异常或自定义异常.我还想删除错误电子邮件.(以便通知我).
我无法访问此类中的当前View Controller(在未捕获的异常情况下).因为它是用委托监听器触发的onUncaughtException(NSException* exception).
如何访问当前视图控制器,或者失败,将用户模态重定向到错误视图控制器?
#import "ErrorHelper.h"
#import "ErrorViewController.h"
#import "Global.h"
#import "AppDelegate.h"
@implementation ErrorHelper
+(void) handleUncaughtError:(NSException*) exception
{
NSLog(@"Uncaught exception occurred!");
[self sendErrorEmailIfAppropriate:exception :nil];
[self redirectToErrorPage];
}
+(void) handleCaughtError:(NSException*) exception
{
NSLog(@"Error caught!!");
[self sendErrorEmailIfAppropriate:exception :nil];
[self redirectToErrorPage];
}
+(void) handleCaughtCustomError:(NSString*) ref :(NSString*) details
{
NSLog(@"Custom error caught!!");
//can do conditional branching on @ref, to do appropriate action.
[self sendErrorEmailIfAppropriate:nil :details];
[self redirectToErrorPage];
}
+(void) sendErrorEmailIfAppropriate:(NSException*) exception :(NSString*)details
{
if([[Global get] isInTestMode] || [[Global get] isInLiveMode]) { …Run Code Online (Sandbox Code Playgroud)