Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getter for bugsnag.context #554

Merged
merged 3 commits into from Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
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
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
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
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
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
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