我已经在Ionic 2项目中安装了cordova-fabric-plugin。之后,我在FabricHandlerError中扩展了IonicHandlerError(下面的代码)。问题在于,当缓存的错误到来时,将定义Crashlytics,并且所有功能都出现在控制台中,但是当您使用它们时,它们是未定义的。
import {Injectable} from "@angular/core";
import {IonicErrorHandler } from 'ionic-angular';
import { Crashlytics } from '@ionic-native/fabric';
@Injectable()
export class FabricErrorHandler extends IonicErrorHandler {
constructor (public crashlytics: Crashlytics) {
super();
}
handleError(error: any): void {
console.log('In Fabric Error Handler');
console.log(error);
this.crashlytics.addLog(error.message);
this.crashlytics.sendCrash();
console.log('Crashlytics Sended. Error message: '+ error.message);
super.handleError(error);
}
}
在控制台中停止处理程序错误:
this.crashlytics
Crashlytics {}
__proto__: IonicNativePlugin
addLog: ƒ ()
constructor: ƒ Crashlytics()
recordError: ƒ ()
sendCrash: ƒ ()
sendNonFatalCrash: ƒ ()
setBoolValueForKey: ƒ ()
setFloatValueForKey: ƒ ()
setIntValueForKey: ƒ ()
setStringValueForKey: ƒ ()
setUserEmail: ƒ ()
setUserIdentifier: ƒ ()
setUserName: ƒ ()
__proto__: Object
this.crashlytics.addLog('ERROR TESTING');
undefined
this.crashlytics.sendCrash();
undefined