UNPKG

@nativescript/firebase-crashlytics

Version:
88 lines 2.73 kB
import { firebase, FirebaseApp } from '@nativescript/firebase-core'; import StackTrace from 'stacktrace-js'; let defaultCrashlytics; const fb = firebase(); Object.defineProperty(fb, 'crashlytics', { value: () => { if (!defaultCrashlytics) { defaultCrashlytics = new Crashlytics(); } return defaultCrashlytics; }, writable: false, }); export class Crashlytics { constructor() { if (defaultCrashlytics) { return defaultCrashlytics; } defaultCrashlytics = this; this._native = FIRCrashlytics.crashlytics(); } get native() { return this._native; } get ios() { return this.native; } get app() { if (!this._app) { // @ts-ignore this._app = FirebaseApp.fromNative(this.native.app); } return this._app; } get isCrashlyticsCollectionEnabled() { return this.native.isCrashlyticsCollectionEnabled(); } checkForUnsentReports() { return new Promise((resolve, reject) => { this.native.checkForUnsentReportsWithCompletion((completed) => { resolve(completed); }); }); } crash() { TNSFirebaseCrashlytics.crash(); } deleteUnsentReports() { this.native.deleteUnsentReports(); } didCrashOnPreviousExecution() { return this.native.didCrashDuringPreviousExecution(); } log(message) { this.native.log(message); } recordError(error) { if (error instanceof Error) { StackTrace.fromError(error).then((stack) => { const traceElements = stack.map((item) => FIRStackFrame.stackFrameWithSymbolFileLine(item.functionName || '(anonymous)', item.fileName ?? '', item.lineNumber ?? -1)); const e = FIRExceptionModel.exceptionModelWithNameReason(error.name || 'JavaScriptError', error.message); e.stackTrace = NSArray.arrayWithArray(traceElements); this.native.recordExceptionModel(e); }); } else { this.native.recordError(error); } } sendUnsentReports() { this.native.sendUnsentReports(); } setAttribute(name, value) { this.native.setCustomValueForKey(value, name); } setAttributes(attributes) { Object.keys(attributes).forEach((key) => { this.native.setCustomValueForKey(attributes[key], key); }); } setCrashlyticsCollectionEnabled(enabled) { this.native.setCrashlyticsCollectionEnabled(enabled); } setUserId(userId) { this.native.setUserID(userId); } } //# sourceMappingURL=index.ios.js.map