【发布时间】:2010-11-10 20:12:37
【问题描述】:
我正在使用来自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;
}
但是,这个东西并没有发现很多错误,比如发布错误、访问错误等,并且应用程序消失了。我有 2 个问题不清楚为什么会发生,最终用户也不知道该说什么。
(例如释放两次相同的 var 不捕获)
那么,我如何得到所有这些讨厌的错误,以便最终用户简单地向我发送崩溃报告?
【问题讨论】:
-
另外,是否可以获得带有错误行的完整堆栈跟踪?
-
你真的能让 UIAlertView 显示出来吗?我做不到。有什么建议吗?
标签: iphone error-handling crash