Skip to content

Commit

Permalink
Add iOS recordError
Browse files Browse the repository at this point in the history
  • Loading branch information
nokrasnov committed May 5, 2016
1 parent b9c4a93 commit 50cdb10
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
22 changes: 22 additions & 0 deletions src/ios/FabricPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions typings/cordova-fabric-plugin-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ fabric.Crashlytics.sendCrash();

fabric.Crashlytics.sendNonFatalCrash("Error");

fabric.Crashlytics.recordError("Error", -1);

fabric.Crashlytics.setUserIdentifier("123");

fabric.Crashlytics.setUserName("bob");
Expand Down
5 changes: 5 additions & 0 deletions typings/cordova-fabric-plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
7 changes: 7 additions & 0 deletions www/FabricPlugin.Crashlytics.es6
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class FabricCrashlytics {
]);
}

recordError(message, code) {
window.fabric.core.execPlugin('recordError', [
message,
code
]);
}

setUserIdentifier(userIdentifier) {
window.fabric.core.execPlugin('setUserIdentifier', [
userIdentifier
Expand Down
5 changes: 5 additions & 0 deletions www/FabricPlugin.Crashlytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 50cdb10

Please sign in to comment.