BugsnagClient

Objective-C


@interface BugsnagClient
    : NSObject <BugsnagFeatureFlagStore, BugsnagMetadataStore>

Swift

class BugsnagClient : NSObject, BugsnagFeatureFlagStore, BugsnagMetadataStore

The BugsnagClient is not intended to be used directly.

Use the static access provided by the Bugsnag class instead.

  • Initializes the client with the provided configuration.

    Declaration

    Objective-C

    - (instancetype _Nonnull)initWithConfiguration:
        (BugsnagConfiguration *_Nonnull)configuration;

    Swift

    init(configuration: BugsnagConfiguration)
  • Send a custom or caught exception to Bugsnag. *

    • The exception will be sent to Bugsnag in the background allowing your
    • app to continue running. *
    • - parameter: exception The exception.

    Declaration

    Objective-C

    - (void)notify:(NSException *_Nonnull)exception;

    Swift

    func notify(_ exception: NSException)
  • Send a custom or caught exception to Bugsnag

    Declaration

    Objective-C

    - (void)notify:(NSException *_Nonnull)exception
             block:(BugsnagOnErrorBlock _Nullable)block;

    Swift

    func notify(_ exception: NSException, block: BugsnagOnErrorBlock? = nil)

    Parameters

    exception

    The exception

    block

    A block for optionally configuring the error report

  • Send an error to Bugsnag

    Declaration

    Objective-C

    - (void)notifyError:(NSError *_Nonnull)error;

    Swift

    func notifyError(_ error: Error)

    Parameters

    error

    The error

  • Send an error to Bugsnag

    Declaration

    Objective-C

    - (void)notifyError:(NSError *_Nonnull)error
                  block:(BugsnagOnErrorBlock _Nullable)block;

    Swift

    func notifyError(_ error: Error, block: BugsnagOnErrorBlock? = nil)

    Parameters

    error

    The error

    block

    A block for optionally configuring the error report

  • Leave a “breadcrumb” log message, representing an action that occurred in your app, to aid with debugging.

    Declaration

    Objective-C

    - (void)leaveBreadcrumbWithMessage:(NSString *_Nonnull)message;

    Swift

    func leaveBreadcrumb(withMessage message: String)

    Parameters

    message

    the log message to leave

  • Leave a “breadcrumb” log message each time a notification with a provided name is received by the application

    Declaration

    Objective-C

    - (void)leaveBreadcrumbForNotificationName:(NSString *_Nonnull)notificationName;

    Swift

    func leaveBreadcrumb(forNotificationName notificationName: String)

    Parameters

    notificationName

    name of the notification to capture

  • Leave a “breadcrumb” log message, representing an action that occurred in your app, to aid with debugging, along with additional metadata and a type.

    Declaration

    Objective-C

    - (void)leaveBreadcrumbWithMessage:(NSString *_Nonnull)message
                              metadata:(NSDictionary *_Nullable)metadata
                               andType:(BSGBreadcrumbType)type;

    Swift

    func leaveBreadcrumb(_ message: String, metadata: [AnyHashable : Any]?, type: BSGBreadcrumbType)

    Parameters

    message

    The log message to leave.

    metadata

    Diagnostic data relating to the breadcrumb. Values should be serializable to JSON with NSJSONSerialization.

    type

    A BSGBreadcrumbTypeValue denoting the type of breadcrumb.

  • Leave a “breadcrumb” log message representing a completed network request.

    Declaration

    Objective-C

    - (void)leaveNetworkRequestBreadcrumbForTask:(nonnull NSURLSessionTask *)task
                                         metrics:(nonnull NSURLSessionTaskMetrics *)
                                                     metrics;

    Swift

    func leaveNetworkRequestBreadcrumb(task: URLSessionTask, metrics: URLSessionTaskMetrics)
  • Returns the current buffer of breadcrumbs that will be sent with captured events. This ordered list represents the most recent breadcrumbs to be captured up to the limit set in BugsnagConfiguration.maxBreadcrumbs

    Declaration

    Objective-C

    - (nonnull NSArray<BugsnagBreadcrumb *> *)breadcrumbs;

    Swift

    func breadcrumbs() -> [BugsnagBreadcrumb]
  • Starts tracking a new session.

    By default, sessions are automatically started when the application enters the foreground. If you wish to manually call startSession at the appropriate time in your application instead, the default behaviour can be disabled via autoTrackSessions.

    Any errors which occur in an active session count towards your application’s stability score. You can prevent errors from counting towards your stability score by calling pauseSession and resumeSession at the appropriate time in your application.

    See

    pauseSession:

    See

    resumeSession:

    Declaration

    Objective-C

    - (void)startSession;

    Swift

    func startSession()
  • Stops tracking a session.

    When a session is stopped, errors will not count towards your application’s stability score. This can be advantageous if you do not wish these calculations to include a certain type of error, for example, a crash in a background service. You should disable automatic session tracking via autoTrackSessions if you call this method.

    A stopped session can be resumed by calling resumeSession, which will make any subsequent errors count towards your application’s stability score. Alternatively, an entirely new session can be created by calling startSession.

    See

    startSession:

    See

    resumeSession:

    Declaration

    Objective-C

    - (void)pauseSession;

    Swift

    func pauseSession()
  • Resumes a session which has previously been stopped, or starts a new session if none exists.

    If a session has already been resumed or started and has not been stopped, calling this method will have no effect. You should disable automatic session tracking via autoTrackSessions if you call this method.

    It’s important to note that sessions are stored in memory for the lifetime of the application process and are not persisted on disk. Therefore calling this method on app startup would start a new session, rather than continuing any previous session.

    You should call this at the appropriate time in your application when you wish to resume a previously started session. Any subsequent errors which occur in your application will be reported to Bugsnag and will count towards your application’s stability score.

    See

    startSession:

    See

    pauseSession:

    Declaration

    Objective-C

    - (BOOL)resumeSession;

    Swift

    func resumeSession() -> Bool

    Return Value

    true if a previous session was resumed, false if a new session was started.

  • Add a callback to be invoked before a session is sent to Bugsnag.

    @returns An opaque reference to the callback which can be passed to removeOnSession:

    Declaration

    Objective-C

    - (nonnull BugsnagOnSessionRef)addOnSessionBlock:
        (nonnull BugsnagOnSessionBlock)block;

    Swift

    func addOnSession(block: @escaping BugsnagOnSessionBlock) -> BugsnagOnSessionRef

    Parameters

    block

    A block which can modify the session

  • Remove a callback that would be invoked before a session is sent to Bugsnag.

    Declaration

    Objective-C

    - (void)removeOnSession:(nonnull BugsnagOnSessionRef)callback;

    Swift

    func removeOnSession(_ callback: BugsnagOnSessionRef)

    Parameters

    callback

    The opaque reference of the callback, returned by addOnSessionBlock:

  • Deprecated

    Deprecated

    Declaration

    Objective-C

    - (void)removeOnSessionBlock:(BugsnagOnSessionBlock _Nonnull)block;

    Swift

    func removeOnSession(block: @escaping BugsnagOnSessionBlock)
  • Retrieves the context - a general summary of what was happening in the application

    Declaration

    Objective-C

    @property (copy, nullable) NSString *context;

    Swift

    var context: String? { get set }
  • Deprecated

    Declaration

    Objective-C

    - (BOOL)appDidCrashLastLaunch;

    Swift

    func appDidCrashLastLaunch() -> Bool

    Return Value

    YES if Bugsnag has been started and the previous launch crashed

  • Information about the last run of the app, and whether it crashed.

    Declaration

    Objective-C

    @property (nonatomic, readonly, nullable) BugsnagLastRunInfo *lastRunInfo;

    Swift

    var lastRunInfo: BugsnagLastRunInfo? { get }
  • Tells Bugsnag that your app has finished launching.

    Errors reported after calling this method will have the BugsnagAppWithState.isLaunching property set to false.

    Declaration

    Objective-C

    - (void)markLaunchCompleted;

    Swift

    func markLaunchCompleted()
  • The current user

    Declaration

    Objective-C

    - (BugsnagUser *_Nonnull)user;

    Swift

    func user() -> BugsnagUser
  • Set user metadata

    Declaration

    Objective-C

    - (void)setUser:(NSString *_Nullable)userId
          withEmail:(NSString *_Nullable)email
            andName:(NSString *_Nullable)name;

    Swift

    func setUser(_ userId: String?, withEmail email: String?, andName name: String?)

    Parameters

    userId

    ID of the user

    name

    Name of the user

    email

    Email address of the user

  • Add a callback to be invoked when a breadcrumb is captured by Bugsnag, to change the breadcrumb contents as needed

    @returns An opaque reference to the callback which can be passed to removeOnBreadcrumb:

    Declaration

    Objective-C

    - (nonnull BugsnagOnBreadcrumbRef)addOnBreadcrumbBlock:
        (nonnull BugsnagOnBreadcrumbBlock)block;

    Swift

    func addOnBreadcrumb(block: @escaping BugsnagOnBreadcrumbBlock) -> BugsnagOnBreadcrumbRef

    Parameters

    block

    A block which returns YES if the breadcrumb should be captured

  • Remove the callback that would be invoked when a breadcrumb is captured.

    Declaration

    Objective-C

    - (void)removeOnBreadcrumb:(nonnull BugsnagOnBreadcrumbRef)callback;

    Swift

    func removeOnBreadcrumb(_ callback: BugsnagOnBreadcrumbRef)

    Parameters

    callback

    The opaque reference of the callback, returned by addOnBreadcrumbBlock:

  • Deprecated

    Deprecated

    Declaration

    Objective-C

    - (void)removeOnBreadcrumbBlock:(BugsnagOnBreadcrumbBlock _Nonnull)block;

    Swift

    func removeOnBreadcrumb(block: @escaping BugsnagOnBreadcrumbBlock)