Skip to content

Commit

Permalink
Merge pull request #554 from bugsnag/v6-context
Browse files Browse the repository at this point in the history
Add getter for bugsnag.context
  • Loading branch information
fractalwrench committed Apr 22, 2020
2 parents 64331f4 + af370e3 commit 365f463
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Bugsnag Notifiers on other platforms.

## Enhancements

* Add getter for `Bugsnag.context`
[#554](https://github.com/bugsnag/bugsnag-cocoa/pull/554)

* Make `BugsnagUser` properties readonly
[#556](https://github.com/bugsnag/bugsnag-cocoa/pull/556)

Expand Down
9 changes: 6 additions & 3 deletions Source/Bugsnag.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,15 @@
// =============================================================================

/**
* 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;

/**
* Retrieves the context - a general summary of what was happening in the application
*/
+ (NSString *_Nullable)context;

// =============================================================================
// MARK: - User
// =============================================================================
Expand Down
7 changes: 7 additions & 0 deletions Source/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ + (void)setContext:(NSString *_Nullable)context {
}
}

+ (NSString *_Nullable)context {
if ([self bugsnagStarted]) {
return self.client.context;
}
return nil;
}

+ (BugsnagUser *)user {
return self.client.user;
}
Expand Down
6 changes: 2 additions & 4 deletions Source/BugsnagClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Source/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions Tests/BugsnagClientMirrorTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
]];
}

Expand Down

0 comments on commit 365f463

Please sign in to comment.