@@ -51,9 +51,13 @@ + (void)startBugsnagWithApiKey:(NSString *)apiKey {
5151
5252+ (void )startBugsnagWithConfiguration : (BugsnagConfiguration *)configuration {
5353 @synchronized (self) {
54- bsg_g_bugsnag_notifier =
55- [[BugsnagNotifier alloc ] initWithConfiguration: configuration];
56- [bsg_g_bugsnag_notifier start ];
54+ if ([configuration hasValidApiKey ]) {
55+ bsg_g_bugsnag_notifier =
56+ [[BugsnagNotifier alloc ] initWithConfiguration: configuration];
57+ [bsg_g_bugsnag_notifier start ];
58+ } else {
59+ bsg_log_err (@" Bugsnag not initialized - a valid API key must be supplied." );
60+ }
5761 }
5862}
5963
@@ -73,75 +77,87 @@ + (BugsnagNotifier *)notifier {
7377}
7478
7579+ (void )notify : (NSException *)exception {
76- [self .notifier notifyException: exception
77- block: ^(BugsnagCrashReport *_Nonnull report) {
78- report.depth += 2 ;
79- }];
80+ if ([self bugsnagStarted ]) {
81+ [self .notifier notifyException: exception
82+ block: ^(BugsnagCrashReport *_Nonnull report) {
83+ report.depth += 2 ;
84+ }];
85+ }
8086}
8187
8288+ (void )notify : (NSException *)exception block : (BugsnagNotifyBlock)block {
83- [[self notifier ] notifyException: exception
84- block: ^(BugsnagCrashReport *_Nonnull report) {
85- report.depth += 2 ;
86-
87- if (block) {
88- block (report);
89- }
90- }];
89+ if ([self bugsnagStarted ]) {
90+ [[self notifier ] notifyException: exception
91+ block: ^(BugsnagCrashReport *_Nonnull report) {
92+ report.depth += 2 ;
93+
94+ if (block) {
95+ block (report);
96+ }
97+ }];
98+ }
9199}
92100
93101+ (void )notifyError : (NSError *)error {
94- [self .notifier notifyError: error
95- block: ^(BugsnagCrashReport *_Nonnull report) {
96- report.depth += 2 ;
97- }];
102+ if ([self bugsnagStarted ]) {
103+ [self .notifier notifyError: error
104+ block: ^(BugsnagCrashReport *_Nonnull report) {
105+ report.depth += 2 ;
106+ }];
107+ }
98108}
99109
100110+ (void )notifyError : (NSError *)error block : (BugsnagNotifyBlock)block {
101- [[self notifier ] notifyError: error
102- block: ^(BugsnagCrashReport *_Nonnull report) {
103- report.depth += 2 ;
104-
105- if (block) {
106- block (report);
107- }
108- }];
111+ if ([self bugsnagStarted ]) {
112+ [[self notifier ] notifyError: error
113+ block: ^(BugsnagCrashReport *_Nonnull report) {
114+ report.depth += 2 ;
115+
116+ if (block) {
117+ block (report);
118+ }
119+ }];
120+ }
109121}
110122
111123+ (void )notify : (NSException *)exception withData : (NSDictionary *)metaData {
112-
113- [[self notifier ]
114- notifyException: exception
115- block: ^(BugsnagCrashReport *_Nonnull report) {
116- report.depth += 2 ;
117- report.metaData = [metaData
118- BSG_mergedInto: [self .notifier.configuration
119- .metaData toDictionary ]];
120- }];
124+ if ([self bugsnagStarted ]) {
125+ [[self notifier ]
126+ notifyException: exception
127+ block: ^(BugsnagCrashReport *_Nonnull report) {
128+ report.depth += 2 ;
129+ report.metaData = [metaData
130+ BSG_mergedInto: [self .notifier.configuration
131+ .metaData toDictionary ]];
132+ }];
133+ }
121134}
122135
123136+ (void )notify : (NSException *)exception
124137 withData : (NSDictionary *)metaData
125138 atSeverity : (NSString *)severity {
126-
127- [[self notifier ]
128- notifyException: exception
129- atSeverity: BSGParseSeverity (severity)
130- block: ^(BugsnagCrashReport *_Nonnull report) {
131- report.depth += 2 ;
132- report.metaData = [metaData
133- BSG_mergedInto: [self .notifier.configuration
134- .metaData toDictionary ]];
135- report.severity = BSGParseSeverity (severity);
136- }];
139+ if ([self bugsnagStarted ]) {
140+ [[self notifier ]
141+ notifyException: exception
142+ atSeverity: BSGParseSeverity (severity)
143+ block: ^(BugsnagCrashReport *_Nonnull report) {
144+ report.depth += 2 ;
145+ report.metaData = [metaData
146+ BSG_mergedInto: [self .notifier.configuration
147+ .metaData toDictionary ]];
148+ report.severity = BSGParseSeverity (severity);
149+ }];
150+ }
137151}
138152
139153+ (void )internalClientNotify : (NSException *_Nonnull)exception
140154 withData : (NSDictionary *_Nullable)metaData
141155 block : (BugsnagNotifyBlock _Nullable)block {
142- [self .notifier internalClientNotify: exception
143- withData: metaData
144- block: block];
156+ if ([self bugsnagStarted ]) {
157+ [self .notifier internalClientNotify: exception
158+ withData: metaData
159+ block: block];
160+ }
145161}
146162
147163+ (void )addAttribute : (NSString *)attributeName
@@ -161,7 +177,7 @@ + (void)clearTabWithName:(NSString *)tabName {
161177}
162178
163179+ (BOOL )bugsnagStarted {
164- if (self.notifier == nil ) {
180+ if (! self.notifier . started ) {
165181 bsg_log_err (@" Ensure you have started Bugsnag with startWithApiKey: "
166182 @" before calling any other Bugsnag functions." );
167183
@@ -171,31 +187,43 @@ + (BOOL)bugsnagStarted {
171187}
172188
173189+ (void )leaveBreadcrumbWithMessage : (NSString *)message {
174- [self leaveBreadcrumbWithBlock: ^(BugsnagBreadcrumb *_Nonnull crumbs) {
175- crumbs.metadata = @{BSGKeyMessage : message};
176- }];
190+ if ([self bugsnagStarted ]) {
191+ [self leaveBreadcrumbWithBlock: ^(BugsnagBreadcrumb *_Nonnull crumbs) {
192+ crumbs.metadata = @{BSGKeyMessage: message};
193+ }];
194+ }
177195}
178196
179197+ (void )leaveBreadcrumbWithBlock :
180198 (void (^_Nonnull)(BugsnagBreadcrumb *_Nonnull))block {
181- [self .notifier addBreadcrumbWithBlock: block];
199+ if ([self bugsnagStarted ]) {
200+ [self .notifier addBreadcrumbWithBlock: block];
201+ }
182202}
183203
184204+ (void )leaveBreadcrumbForNotificationName :
185205 (NSString *_Nonnull)notificationName {
186- [self .notifier crumbleNotification: notificationName];
206+ if ([self bugsnagStarted ]) {
207+ [self .notifier crumbleNotification: notificationName];
208+ }
187209}
188210
189211+ (void )setBreadcrumbCapacity : (NSUInteger )capacity {
190- self.notifier .configuration .breadcrumbs .capacity = capacity;
212+ if ([self bugsnagStarted ]) {
213+ self.notifier .configuration .breadcrumbs .capacity = capacity;
214+ }
191215}
192216
193217+ (void )clearBreadcrumbs {
194- [self .notifier clearBreadcrumbs ];
218+ if ([self bugsnagStarted ]) {
219+ [self .notifier clearBreadcrumbs ];
220+ }
195221}
196222
197223+ (void )startSession {
198- [self .notifier startSession ];
224+ if ([self bugsnagStarted ]) {
225+ [self .notifier startSession ];
226+ }
199227}
200228
201229+ (NSDateFormatter *)payloadDateFormatter {
@@ -209,23 +237,31 @@ + (NSDateFormatter *)payloadDateFormatter {
209237}
210238
211239+ (void )setSuspendThreadsForUserReported : (BOOL )suspendThreadsForUserReported {
212- [[BSG_KSCrash sharedInstance ]
213- setSuspendThreadsForUserReported: suspendThreadsForUserReported];
240+ if ([self bugsnagStarted ]) {
241+ [[BSG_KSCrash sharedInstance ]
242+ setSuspendThreadsForUserReported: suspendThreadsForUserReported];
243+ }
214244}
215245
216246+ (void )setReportWhenDebuggerIsAttached : (BOOL )reportWhenDebuggerIsAttached {
217- [[BSG_KSCrash sharedInstance ]
218- setReportWhenDebuggerIsAttached: reportWhenDebuggerIsAttached];
247+ if ([self bugsnagStarted ]) {
248+ [[BSG_KSCrash sharedInstance ]
249+ setReportWhenDebuggerIsAttached: reportWhenDebuggerIsAttached];
250+ }
219251}
220252
221253+ (void )setThreadTracingEnabled : (BOOL )threadTracingEnabled {
222- [[BSG_KSCrash sharedInstance ] setThreadTracingEnabled: threadTracingEnabled];
254+ if ([self bugsnagStarted ]) {
255+ [[BSG_KSCrash sharedInstance ] setThreadTracingEnabled: threadTracingEnabled];
256+ }
223257}
224258
225259+ (void )setWriteBinaryImagesForUserReported :
226260 (BOOL )writeBinaryImagesForUserReported {
227- [[BSG_KSCrash sharedInstance ]
228- setWriteBinaryImagesForUserReported: writeBinaryImagesForUserReported];
261+ if ([self bugsnagStarted ]) {
262+ [[BSG_KSCrash sharedInstance ]
263+ setWriteBinaryImagesForUserReported: writeBinaryImagesForUserReported];
264+ }
229265}
230266
231267@end
0 commit comments