3

我想要的是自己捕获所有崩溃和异常并添加其他信息(例如用户)来保存它。现在,我的想法是将 try-catch 块包装在 didFinishLaunchingWithOptions 中。在 catch 块中,我记录异常和附加信息,然后重新抛出它。这是实现它的正确方法吗?提前致谢。

更新代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
@try {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    self.loginViewController = [[LoginViewController alloc] init];
    self.window.rootViewController = self.loginViewController;
    [self.window makeKeyAndVisible];
}
@catch (NSException *exception) {
    // Save the exception description and additional info here
    ...
    // And re-throw it.
    [exception raise];
}
    return YES;

}

进一步更新:我自己尝试过上面的代码,它无法捕捉到其他地方发生的异常。我知道谷歌分析 iOS SDK 有“sendUncaughtExceptions”属性来做类似的事情。我认为如果我自己实现类似的功能可以提供更大的灵活性,因为我们有自己的错误服务器(我会将错误日志上传到我们的服务器)。任何建议表示赞赏。

解决方案:最后,我从这个博客中得到了一个解决方案:http: //www.cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html

4

1 回答 1

0

您是否查看过 TestFlight API?它非常容易实现,免费,听起来它会完成你想要的。它具有内置的远程异常处理和远程日志记录(您只需像使用 NSLog 一样使用 TFLog)。您可以记录 UDID 并跟踪用户以进行测试版或企业分发,但请注意 Apple 不允许您在应用商店应用中收集 UDID,因此您必须在该版本中禁用它——您仍然会崩溃日志和其他指标,它们只是匿名的。

www.testflightapp.com

于 2013-04-22T05:22:41.560 回答