ios - 如何在 iOS 上报告 Firebase 崩溃的非致命异常?

标签 ios swift firebase crashlytics firebase-crash-reporting

如何使用 Firebase 崩溃报告在 iOS 上报告非致命异常?在 Android 中,我们可以这样做:

 FirebaseCrash.report(new Exception("My first Firebase non-fatal error on Android"));

最佳答案

您现在可以在 Firebase Crashlytics 中记录非致命异常

因此,接受的答案不再正确。可以使用以下 Firebase Crashlytics 方法记录非致命异常:

Crashlytics.crashlytics().record(error: error)

来自 the documentation :

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.


示例用法:

let userInfo: [String: String] = [
    "deviceId": "someDeviceId",
    "localizedDescription": yourException.localizedDescription,
    "anotherKey": "anotherValue"
]

let domain = "METHOD: some/domain/that/just/had-an-exception"
let code = 404

let error = NSError(domain: domain, code: code, userInfo: userInfo)

Crashlytics.crashlytics().record(error: error)

domain 是在 Firebase 中使用的一些漂亮的标识符(例如方法 + 请求路径),code 是异常的状态代码(这里是 404),并且userInfo 附加数据被转换为键值对并显示在单个问题的键/日志部分。

注意:记录的错误按 NSError domaincode 分组(与 fatals 不同,后者在 Firebase 中按堆栈跟踪分组)。


Firebase Console > Crashlytics 中的示例输出:

Example output showing non-fatal exceptions in Firebase Crashlytics console

控制台中的问题详情页面(显示 userInfo 键值对):

Example details view of a non-fatal exception issue in the Firebase Crashlytics console (showing userInfo key-value pairs)

关于ios - 如何在 iOS 上报告 Firebase 崩溃的非致命异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43853090/

相关文章:

iphone - 是否可以检测到状态栏时钟上的 "Minute"何时发生变化?

swift - 无法将 NSButton 添加到 Sprite-Kit 场景

ios - UIView 动画完成 block 以 TRUE 调用两次

java - 根据 Android 中其他微调器的选择填充微调器

java - 在 Firebase 类中找不到名称的 setter /字段

ios - 如何展开到导航堆栈上的第一个 View Controller

ios - 如何在 SwiftUI 中删除 `Form` 的左右填充?

ios - 如何使用GCD控制动画序列

swift - 将枚举类型的值与关联值进行比较时出现编译器错误?

javascript - Uncaught Error : No Storage Bucket defined in Firebase Options.(网络)