如何使用 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 domain
和 code
分组(与 fatals 不同,后者在 Firebase 中按堆栈跟踪分组)。
Firebase Console > Crashlytics
中的示例输出:
控制台中的问题详情页面(显示 userInfo
键值对):
关于ios - 如何在 iOS 上报告 Firebase 崩溃的非致命异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43853090/