我找到了在Crashlytics Android SDK中记录自定义捕获异常的方法,但是我找不到类似的方法适用于iOS SDK。是否有一种方法可以在iOS上使用Crashlytics记录已捕获的异常?
请参见Android解释:http://support.crashlytics.com/knowledgebase/articles/202805-logging-caught-exceptions
我找到了在Crashlytics Android SDK中记录自定义捕获异常的方法,但是我找不到类似的方法适用于iOS SDK。是否有一种方法可以在iOS上使用Crashlytics记录已捕获的异常?
请参见Android解释:http://support.crashlytics.com/knowledgebase/articles/202805-logging-caught-exceptions
我是来自Crashlytics和Fabric的Mike。
现在您可以在iOS、tvOS或OS X应用中捕获已记录的NSErrors。您应该使用:
[CrashlyticsKit recordError:error];
或者Crashlytics.sharedInstance().recordError(error)
这将让您在每个用户会话中捕获相当数量的已记录 NSErrors。这些仅在应用程序重新启动时发送。记录的错误按错误域和代码分组。这意味着错误问题可能涉及许多不同的调用站点。
请参见文档
终于,Crashlytics在3.5.0版本中添加了所需的功能!!
[CrashlyticsKit recordError:error];
或者
Crashlytics.sharedInstance().recordError(error)
参考资料
/**
*
* This allows you to record a non-fatal event, described by an NSError object. These events will be grouped and
* displayed similarly to crashes. Keep in mind that this method can be expensive. Also, the total number of
* NSErrors that can be recorded during your app's life-cycle is limited by a fixed-size circular buffer. If the
* buffer is overrun, the oldest data is dropped. Errors are relayed to Crashlytics on a subsequent launch
* of your application.
*
* You can also use the -recordError:withAdditionalUserInfo: to include additional context not represented
* by the NSError instance itself.
*
**/
- (void)recordError:(NSError *)error;
- (void)recordError:(NSError *)error withAdditionalUserInfo:(nullable CLS_GENERIC_NSDICTIONARY(NSString *, id) *)userInfo;
https://docs.fabric.io/ios/changelog.html#january-7-2016
历史记录
实际上,这并不像我期望的那样工作:消息被保存到Crashlytics中,但只有在应用程序重新启动后才会保存最后一条消息。
到目前为止,这里提到的解决方案都没有奏效。在iOS中使用Crashlytics无法跟踪处理过的异常。
您可以使用此功能来记录任何异常
[[Crashlytics sharedInstance] recordCustomExceptionName:@"HandledException" reason:@"Some reason" frameArray:@[]];
NON-FATALS
类型显示。recordCustomExceptionName:reason:frameArray:
此方法可用于记录报告中的单个异常结构。当代码与Lua,C#或Javascript等非本机语言交互时,这特别有用。此调用可能很昂贵,仅应在进程终止前短时间内使用。此API不适用于记录NSException对象。所有安全可报告的NSExceptions都会被Crashlytics自动捕获。
使用Crashlytics SDK在iOS中捕获异常无法记录日志。可以使用CLS_LOG记录自定义消息,但这些日志消息只会在下一次崩溃数据上传到Crashlytics时才会被记录。如果没有崩溃,这些日志消息将永远不会出现在Crashlytics仪表板中。我从Crashlytics支持团队得到了官方确认。在iOS中记录捕获的异常是他们未来计划中的一项。
我已经查看了不同的网站,寻求IOS系统下Crashlytics的替代选项。
我发现crittercism目前是最好的选择。@Dima 我认为它是Crashlytics的替代方案,请试用一下。
以下链接对于将crittercism集成到您的项目中很有帮助...!
http://docs.crittercism.com/ios/ios.html#logging-handled-exceptions
http://www.raywenderlich.com/34050/overview-of-ios-crash-reporting-tools-part-2
@try {
}
@catch (NSException *exc)
{
[Crittercism logHandledException:exc]
}
请参考这些链接,看看它们对你是否有用...!
在catch块中使用以下行来处理自定义捕获的异常
NSUncaughtExceptionHandler *handler = NSGetUncaughtExceptionHandler();
handler(exception);
CLS_LOG
(请参阅文档)来记录某些消息,它们将被添加到下一个崩溃报告中。 - vrwimrecordError
,我编写了自己的全局recordException
,用于处理我知道不会致命的 try/catch 块。 - Jacksonkr