From 50cdb106fc5008e07f45eed7325d1118fc150ab5 Mon Sep 17 00:00:00 2001 From: Nikita Krasnov Date: Thu, 5 May 2016 18:27:09 +0300 Subject: [PATCH] Add iOS recordError --- README.md | 16 ++++++++++++++++ src/ios/FabricPlugin.m | 22 ++++++++++++++++++++++ typings/cordova-fabric-plugin-tests.ts | 2 ++ typings/cordova-fabric-plugin.d.ts | 5 +++++ www/FabricPlugin.Crashlytics.es6 | 7 +++++++ www/FabricPlugin.Crashlytics.js | 5 +++++ 6 files changed, 57 insertions(+) diff --git a/README.md b/README.md index 15a3b03..a647605 100755 --- a/README.md +++ b/README.md @@ -44,6 +44,22 @@ window.fabric.Crashlytics.addLog("about to send a crash for testing!"); window.fabric.Crashlytics.sendCrash(); ``` +## Send a Non Fatal Crash / Recording Errors + +```javascript +//Android and iOS +window.fabric.Crashlytics.addLog("about to send a non fatal crash for testing!"); +window.fabric.Crashlytics.sendNonFatalCrash("Error message"); + +//iOS only. Send message and error code +window.fabric.Crashlytics.addLog("about to send a non fatal crash for testing!"); +window.fabric.Crashlytics.recordError("Error message", -1); +``` + +Issue Grouping + +Crashes are grouped via stack trace analysis. Logged errors are grouped, instead, by the error domain and code. Remember that this means error issues can span many different call sites. + ## Set Information for Crash Reports ```javascript window.fabric.Crashlytics.setUserIdentifier("123"); diff --git a/src/ios/FabricPlugin.m b/src/ios/FabricPlugin.m index e691ac9..0b19210 100755 --- a/src/ios/FabricPlugin.m +++ b/src/ios/FabricPlugin.m @@ -36,6 +36,8 @@ - (void)setStringValueForKey:(CDVInvokedUrlCommand*)command; - (void)setIntValueForKey:(CDVInvokedUrlCommand*)command; - (void)setBoolValueForKey:(CDVInvokedUrlCommand*)command; - (void)setFloatValueForKey:(CDVInvokedUrlCommand*)command; +- (void)recordError:(CDVInvokedUrlCommand*)command; +- (void)sendNonFatalCrash:(CDVInvokedUrlCommand*)command; @end @@ -290,4 +292,24 @@ - (void)setFloatValueForKey:(CDVInvokedUrlCommand*)command } } +- (void)recordError:(CDVInvokedUrlCommand*)command +{ + NSString *description = NSLocalizedString([command argumentAtIndex:0 withDefault:@"No Message Provided"], nil); + NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: description }; + + NSNumber *defaultCode = [NSNumber numberWithInt:-1]; + int code = [[command argumentAtIndex:1 withDefault:defaultCode] intValue]; + + NSString *domain = [[NSBundle mainBundle] bundleIdentifier]; + + NSError *error = [NSError errorWithDomain: domain code: code userInfo: userInfo]; + + [[Crashlytics sharedInstance] recordError:error]; +} + +- (void)sendNonFatalCrash:(CDVInvokedUrlCommand*)command +{ + [self recordError: command]; +} + @end diff --git a/typings/cordova-fabric-plugin-tests.ts b/typings/cordova-fabric-plugin-tests.ts index 54b79ec..6464cc5 100644 --- a/typings/cordova-fabric-plugin-tests.ts +++ b/typings/cordova-fabric-plugin-tests.ts @@ -10,6 +10,8 @@ fabric.Crashlytics.sendCrash(); fabric.Crashlytics.sendNonFatalCrash("Error"); +fabric.Crashlytics.recordError("Error", -1); + fabric.Crashlytics.setUserIdentifier("123"); fabric.Crashlytics.setUserName("bob"); diff --git a/typings/cordova-fabric-plugin.d.ts b/typings/cordova-fabric-plugin.d.ts index 45c40ec..668f772 100644 --- a/typings/cordova-fabric-plugin.d.ts +++ b/typings/cordova-fabric-plugin.d.ts @@ -45,6 +45,11 @@ declare module FabricPlugin { */ sendNonFatalCrash(message: string): void; + /** + * Used to record a non-fatal error message (iOS only). + */ + recordError(message: string, code: number): void; + /** * Sets the user's identifier for logging to Crashlytics backend. */ diff --git a/www/FabricPlugin.Crashlytics.es6 b/www/FabricPlugin.Crashlytics.es6 index d23ba89..d6dbd03 100644 --- a/www/FabricPlugin.Crashlytics.es6 +++ b/www/FabricPlugin.Crashlytics.es6 @@ -19,6 +19,13 @@ class FabricCrashlytics { ]); } + recordError(message, code) { + window.fabric.core.execPlugin('recordError', [ + message, + code + ]); + } + setUserIdentifier(userIdentifier) { window.fabric.core.execPlugin('setUserIdentifier', [ userIdentifier diff --git a/www/FabricPlugin.Crashlytics.js b/www/FabricPlugin.Crashlytics.js index 04b6f20..dbf3fca 100644 --- a/www/FabricPlugin.Crashlytics.js +++ b/www/FabricPlugin.Crashlytics.js @@ -24,6 +24,11 @@ var FabricCrashlytics = (function () { value: function sendNonFatalCrash(message) { window.fabric.core.execPlugin('sendNonFatalCrash', [message]); } + }, { + key: 'recordError', + value: function recordError(message, code) { + window.fabric.core.execPlugin('recordError', [message, code]); + } }, { key: 'setUserIdentifier', value: function setUserIdentifier(userIdentifier) {