Implement sendError for Android

This commit is contained in:
Aleksei Androsov 2017-09-30 17:50:02 +03:00
parent 60d2a2b63e
commit 8c036a64b7
3 changed files with 14 additions and 2 deletions

View File

@ -38,4 +38,7 @@ AppMetrica.activateWithApiKey('...KEY...');
// Sends a custom event message and additional parameters (optional).
AppMetrica.reportEvent('My event');
AppMetrica.reportEvent('My event', { foo: 'bar' });
// Send a custom error event
AppMetrica.reportError('My error');
```

View File

@ -41,6 +41,15 @@ public class AppMetricaModule extends ReactContextBaseJavaModule {
}
}
@ReactMethod
public void reportError(String message) {
try {
Integer.valueOf("00xffWr0ng");
} catch (Throwable error) {
YandexMetrica.reportError(message, error);
}
}
@ReactMethod
public void reportEvent(String message, @Nullable ReadableMap params) {
if (params != null) {

View File

@ -22,8 +22,8 @@ RCT_EXPORT_METHOD(reportEvent:(NSString *)message parameters:(nullable NSDiction
[YMMYandexMetrica reportEvent:message parameters:params onFailure:NULL];
}
RCT_EXPORT_METHOD(reportError:(NSString *)message reason:(NSString *)reason) {
NSException *exception = [[NSException alloc] initWithName:message reason:reason userInfo:nil];
RCT_EXPORT_METHOD(reportError:(NSString *)message) {
NSException *exception = [[NSException alloc] initWithName:message reason:nil userInfo:nil];
[YMMYandexMetrica reportError:message exception:exception onFailure:NULL];
}
@end