From 2aca132f94f2483608d2385c7d3d2ecd02c9ca4c Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Tue, 21 Apr 2020 15:07:21 +0100 Subject: [PATCH 1/2] feat: add getter for bugsnag.context --- Source/Bugsnag.h | 6 +++--- Source/Bugsnag.m | 7 +++++++ Source/BugsnagClient.h | 6 ++---- Source/BugsnagClient.m | 4 ++++ Tests/BugsnagClientMirrorTest.m | 6 ++++-- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Source/Bugsnag.h b/Source/Bugsnag.h index bc608e341..f588d0245 100644 --- a/Source/Bugsnag.h +++ b/Source/Bugsnag.h @@ -217,12 +217,12 @@ // ============================================================================= /** - * Replicates BugsnagConfiguration.context - * - * @param context A general summary of what was happening in the application + * Retrieves the context - a general summary of what was happening in the application */ + (void)setContext:(NSString *_Nullable)context; ++ (NSString *_Nullable)getContext; + // ============================================================================= // MARK: - User // ============================================================================= diff --git a/Source/Bugsnag.m b/Source/Bugsnag.m index 91d85220a..433354ab8 100644 --- a/Source/Bugsnag.m +++ b/Source/Bugsnag.m @@ -299,6 +299,13 @@ + (void)setContext:(NSString *_Nullable)context { } } ++ (NSString *_Nullable)getContext { + if ([self bugsnagStarted]) { + return self.client.context; + } + return nil; +} + + (BugsnagUser *)user { return self.client.user; } diff --git a/Source/BugsnagClient.h b/Source/BugsnagClient.h index 1ba215d88..50e31d69c 100644 --- a/Source/BugsnagClient.h +++ b/Source/BugsnagClient.h @@ -204,11 +204,9 @@ NS_SWIFT_NAME(leaveBreadcrumb(_:metadata:type:)); // ============================================================================= /** - * Replicates BugsnagConfiguration.context - * - * @param context A general summary of what was happening in the application + * Retrieves the context - a general summary of what was happening in the application */ -- (void)setContext:(NSString *_Nullable)context; + @property NSString *_Nullable context; /** * @return YES if Bugsnag has been started and the previous launch crashed diff --git a/Source/BugsnagClient.m b/Source/BugsnagClient.m index f57409388..5441091f8 100644 --- a/Source/BugsnagClient.m +++ b/Source/BugsnagClient.m @@ -748,6 +748,10 @@ - (void)setContext:(NSString *_Nullable)context { self.configuration.context = context; } +- (NSString *)context { + return self.configuration.context; +} + // MARK: - Notify - (void)notifyError:(NSError *_Nonnull)error { diff --git a/Tests/BugsnagClientMirrorTest.m b/Tests/BugsnagClientMirrorTest.m index 7819970ee..8e941be3d 100644 --- a/Tests/BugsnagClientMirrorTest.m +++ b/Tests/BugsnagClientMirrorTest.m @@ -89,7 +89,8 @@ - (void)setUp { @"setMetadata: v24@0:8@16", @"metadata @16@0:8", @"workspaceBreadcrumbStateEvents @16@0:8", - @"startListeningForWorkspaceStateChangeNotifications: v24@0:8@16" + @"startListeningForWorkspaceStateChangeNotifications: v24@0:8@16", + @"context @16@0:8" ]]; // the following methods are implemented on Bugsnag but do not need to @@ -103,7 +104,8 @@ - (void)setUp { @"client @16@0:8", @"bugsnagStarted B16@0:8", @"bugsnagStarted c16@0:8", - @"leaveBreadcrumbWithBlock: v24@0:8@?16" + @"leaveBreadcrumbWithBlock: v24@0:8@?16", + @"getContext @16@0:8" ]]; } From ae9b0af8ee59d58a28d19a2b9d89e1c78956bcac Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Tue, 21 Apr 2020 16:18:50 +0100 Subject: [PATCH 2/2] address review feedback --- CHANGELOG.md | 3 +++ Source/Bugsnag.h | 5 ++++- Source/Bugsnag.m | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4a8f0ec..b4722b040 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Bugsnag Notifiers on other platforms. ## Enhancements +* Add getter for `Bugsnag.context` + [#554](https://github.com/bugsnag/bugsnag-cocoa/pull/554) + * Add `sendThreads` property to `BugsnagConfiguration` [#549](https://github.com/bugsnag/bugsnag-cocoa/pull/549) diff --git a/Source/Bugsnag.h b/Source/Bugsnag.h index f588d0245..c5ef92277 100644 --- a/Source/Bugsnag.h +++ b/Source/Bugsnag.h @@ -221,7 +221,10 @@ */ + (void)setContext:(NSString *_Nullable)context; -+ (NSString *_Nullable)getContext; +/** + * Retrieves the context - a general summary of what was happening in the application + */ ++ (NSString *_Nullable)context; // ============================================================================= // MARK: - User diff --git a/Source/Bugsnag.m b/Source/Bugsnag.m index 433354ab8..4019771fb 100644 --- a/Source/Bugsnag.m +++ b/Source/Bugsnag.m @@ -299,7 +299,7 @@ + (void)setContext:(NSString *_Nullable)context { } } -+ (NSString *_Nullable)getContext { ++ (NSString *_Nullable)context { if ([self bugsnagStarted]) { return self.client.context; }