Crashlytics iOS - 日志被捕异常

Mag*_*nus 46 cocoa-touch objective-c ios crashlytics twitter-fabric

我找到了一种在Crashlytics Android SDK中记录自定义捕获异常的方法,但我找不到类似iOS SDK的内容.有没有办法在iOS上使用Crashlytics记录捕获的异常?

请参阅Android说明:http://support.crashlytics.com/knowledgebase/articles/202805-logging-caught-exceptions

Mik*_*ell 43

Mike来自Crashlytics和Fabric.

您现在可以在iOS,tvOS或OS X应用程序中捕获已记录的NSErrors.你想用:

[CrashlyticsKit recordError:error];
Run Code Online (Sandbox Code Playgroud)

要么

Crashlytics.sharedInstance().recordError(error)
Run Code Online (Sandbox Code Playgroud)

这将允许您为每个用户会话捕获相当数量的已记录NSErrors.这些仅在应用重新启动时发送.记录的错误错误按错误域和代码分组.这意味着错误问题可以跨越许多不同的呼叫站点.

文档

  • @davis我们不提供直接记录或记录NSException实例的工具.一般来说,Cocoa和Cocoa Touch API不是例外安全的.这意味着使用"@catch"可能会在您的过程中产生非常严重的意外副作用,即使在极度小心使用时也是如此.我们建议您不要在代码中使用"@catch"语句.来自Apple文档:"Cocoa框架通常不是异常安全的.一般模式是异常只保留给程序员错误,并且捕获这种异常的程序应该很快就会退出." (3认同)
  • @MikeBonnell如果用户不再打开应用程序怎么办?所有本地记录的NSErrors都不会被推送到crashlytics服务器吗?如果是这样,并且这些本地记录的错误对于解决问题很重要,是否应将NSErrors记录为Answer事件?请澄清。 (2认同)

7yn*_*k3r 5

最后,Crashlytics添加了所需的功能3.5.0 !!

[CrashlyticsKit recordError:error];
Run Code Online (Sandbox Code Playgroud)

要么

Crashlytics.sharedInstance().recordError(error)
Run Code Online (Sandbox Code Playgroud)

参考

/**
 *
 * 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;
Run Code Online (Sandbox Code Playgroud)

https://docs.fabric.io/ios/changelog.html#january-7-2016


历史

这实际上并不像我预期的那样工作:消息被保存到Crashlytics但只有在应用程序重新启动后它才会保存最后一条消息.

到目前为止,这里提到的解决方案都没有.使用Crashlytics无法在iOS中跟踪处理的异常.


您可以使用它来记录任何异常

[[Crashlytics sharedInstance] recordCustomExceptionName:@"HandledException" reason:@"Some reason" frameArray:@[]];
Run Code Online (Sandbox Code Playgroud)

在Crashlytics中,你会在崩溃报告中看到它但是有NON-FATALS类型.

事件,如果它不是它的预期用法异常以与Android处理的异常相同的方式记录.

这在3.0.7版中可用.

recordCustomExceptionName:原因:frameArray:

此方法可用于在报表中记录单个异常结构.当您的代码与Lua,C#或Javascript等非本地语言交互时,这尤其有用.此调用可能很昂贵,只能在进程终止前不久使用.此API不用于记录NSException对象.Crashlytics会自动捕获所有可安全报告的NSExceptions.

https://docs.fabric.io/appledocs/Crashlytics/Classes/Crashlytics.html#//api/name/recordCustomExceptionName:reason:frameArray:

  • 您是否设法使用了自定义数组类型?无法弄清楚该放什么 (2认同)