Skip to content
This repository was archived by the owner on Sep 14, 2020. It is now read-only.

Commit 593920d

Browse files
committed
fix: Check bugsnag has started on all React Native Cocoa methods
1 parent f47fdd5 commit 593920d

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

cocoa/BugsnagReactNative.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
137137
RCT_EXPORT_MODULE()
138138

139139
RCT_EXPORT_METHOD(notify:(NSDictionary *)options) {
140+
if (![Bugsnag bugsnagStarted]) {
141+
return;
142+
}
143+
140144
NSString *const EXCEPTION_TYPE = @"browserjs";
141145
NSException *exception = [NSException
142146
exceptionWithName:[RCTConvert NSString:options[@"errorClass"]]
@@ -181,21 +185,33 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
181185
}
182186

183187
RCT_EXPORT_METHOD(setUser:(NSDictionary *)userInfo) {
188+
if (![Bugsnag bugsnagStarted]) {
189+
return;
190+
}
184191
NSString *identifier = userInfo[@"id"] ? [RCTConvert NSString:userInfo[@"id"]] : nil;
185192
NSString *name = userInfo[@"name"] ? [RCTConvert NSString:userInfo[@"name"]] : nil;
186193
NSString *email = userInfo[@"email"] ? [RCTConvert NSString:userInfo[@"email"]] : nil;
187194
[[Bugsnag configuration] setUser:identifier withName:name andEmail:email];
188195
}
189196

190197
RCT_EXPORT_METHOD(startSession) {
198+
if (![Bugsnag bugsnagStarted]) {
199+
return;
200+
}
191201
[Bugsnag startSession];
192202
}
193203

194204
RCT_EXPORT_METHOD(clearUser) {
205+
if (![Bugsnag bugsnagStarted]) {
206+
return;
207+
}
195208
[[Bugsnag configuration] setUser:nil withName:nil andEmail:nil];
196209
}
197210

198211
RCT_EXPORT_METHOD(leaveBreadcrumb:(NSDictionary *)options) {
212+
if (![Bugsnag bugsnagStarted]) {
213+
return;
214+
}
199215
[Bugsnag leaveBreadcrumbWithBlock:^(BugsnagBreadcrumb *crumb) {
200216
crumb.name = [RCTConvert NSString:options[@"name"]];
201217
crumb.type = BreadcrumbTypeFromString([RCTConvert NSString:options[@"type"]]);
@@ -258,6 +274,9 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
258274
}
259275

260276
- (void)setNotifierDetails:(NSString *)packageVersion {
277+
if (![Bugsnag bugsnagStarted]) {
278+
return;
279+
}
261280
id notifier = [Bugsnag notifier];
262281
NSDictionary *details = [notifier valueForKey:@"details"];
263282
NSString *version;

0 commit comments

Comments
 (0)