Bugsnag

Objective-C


@interface Bugsnag : NSObject <BugsnagClassLevelMetadataStore>

Swift

class Bugsnag : NSObject, BugsnagClassLevelMetadataStore

Static access to a Bugsnag Client, the easiest way to use Bugsnag in your app.

  • Unavailable

    All Bugsnag access is class-level. Prevent the creation of instances.

    Declaration

    Objective-C

    - (instancetype _Nonnull)init;
  • Start listening for crashes.

    This method initializes Bugsnag with the configuration set in your Info.plist.

    If a Bugsnag apiKey string has not been added to your Info.plist or is empty, an NSException will be thrown to indicate that the configuration is not valid.

    Once successfully initialized, NSExceptions, C++ exceptions, Mach exceptions and signals will be logged to disk before your app crashes. The next time your app launches, these reports will be sent to your Bugsnag dashboard.

    Declaration

    Objective-C

    + (BugsnagClient *_Nonnull)start;

    Swift

    class func start() -> BugsnagClient
  • Start listening for crashes.

    This method initializes Bugsnag with the default configuration and the provided apiKey.

    If apiKey is nil or is empty, an NSException will be thrown to indicate that the configuration is not valid.

    Once successfully initialized, NSExceptions, C++ exceptions, Mach exceptions and signals will be logged to disk before your app crashes. The next time your app launches, these reports will be sent to your Bugsnag dashboard.

    Declaration

    Objective-C

    + (BugsnagClient *_Nonnull)startWithApiKey:(NSString *_Nonnull)apiKey;

    Swift

    class func start(withApiKey apiKey: String) -> BugsnagClient

    Parameters

    apiKey

    The API key from your Bugsnag dashboard.

  • Start listening for crashes.

    This method initializes Bugsnag with the provided configuration object.

    If the configuration’s apiKey is nil or is empty, an NSException will be thrown to indicate that the configuration is not valid.

    Once successfully initialized, NSExceptions, C++ exceptions, Mach exceptions and signals will be logged to disk before your app crashes. The next time your app launches, these reports will be sent to your Bugsnag dashboard.

    Declaration

    Objective-C

    + (BugsnagClient *_Nonnull)startWithConfiguration:
        (BugsnagConfiguration *_Nonnull)configuration;

    Swift

    class func start(with configuration: BugsnagConfiguration) -> BugsnagClient

    Parameters

    configuration

    The configuration to use.

  • Deprecated

    Declaration

    Objective-C

    + (BOOL)appDidCrashLastLaunch;

    Swift

    class func appDidCrashLastLaunch() -> Bool

    Return Value

    YES if Bugsnag has been started and the previous launch crashed

  • Declaration

    Objective-C

    + (BOOL)isStarted;

    Swift

    class func isStarted() -> Bool

    Return Value

    YES if and only if a Bugsnag.start() has been called and Bugsnag has initialized such that any calls to the Bugsnag methods can succeed

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

    Declaration

    Objective-C

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

    Swift

    class 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

    class func markLaunchCompleted()
  • Send a custom or caught exception to Bugsnag.

    The exception will be sent to Bugsnag in the background allowing your app to continue running.

    Declaration

    Objective-C

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

    Swift

    class func notify(_ exception: NSException)

    Parameters

    exception

    The exception.

  • Send a custom or caught exception to Bugsnag

    Declaration

    Objective-C

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

    Swift

    class 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

    class 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

    class 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

    class 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

    class 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

    class 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

    class 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

    + (NSArray<BugsnagBreadcrumb *> *_Nonnull)breadcrumbs;

    Swift

    class 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

    class 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

    class 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

    class func resumeSession() -> Bool

    Return Value

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

  • Retrieves the context - a general summary of what was happening in the application

    Declaration

    Objective-C

    + (void)setContext:(NSString *_Nullable)context;

    Swift

    class func setContext(_ context: String?)
  • Retrieves the context - a general summary of what was happening in the application

    Declaration

    Objective-C

    + (NSString *_Nullable)context;

    Swift

    class func context() -> String?
  • The current user

    Declaration

    Objective-C

    + (BugsnagUser *_Nonnull)user;

    Swift

    class func user() -> BugsnagUser
  • Set user metadata

    If user ID is nil, a Bugsnag-generated Device ID is used for the user.id property of events and sessions.

    Declaration

    Objective-C

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

    Swift

    class 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

  • Undocumented

    Declaration

    Objective-C

    + (void)addFeatureFlagWithName:(nonnull NSString *)name variant:(nullable NSString *)variant
        NS_SWIFT_NAME(addFeatureFlag(name:variant:));

    Swift

    class func addFeatureFlag(name: String, variant: String?)
  • Undocumented

    Declaration

    Objective-C

    + (void)addFeatureFlagWithName:(nonnull NSString *)name
        NS_SWIFT_NAME(addFeatureFlag(name:));

    Swift

    class func addFeatureFlag(name: String)
  • Undocumented

    Declaration

    Objective-C

    + (void)addFeatureFlags:(nonnull NSArray<BugsnagFeatureFlag *> *)featureFlags
        NS_SWIFT_NAME(addFeatureFlags(_:));

    Swift

    class func addFeatureFlags(_ featureFlags: [BugsnagFeatureFlag])
  • Undocumented

    Declaration

    Objective-C

    + (void)clearFeatureFlagWithName:(nonnull NSString *)name
        NS_SWIFT_NAME(clearFeatureFlag(name:));

    Swift

    class func clearFeatureFlag(name: String)
  • Undocumented

    Declaration

    Objective-C

    + (void)clearFeatureFlags;

    Swift

    class func clearFeatureFlags()
  • 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

    class 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

    class 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

    class func removeOnSession(block: @escaping BugsnagOnSessionBlock)
  • 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

    class 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

    class 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

    class func removeOnBreadcrumb(block: @escaping BugsnagOnBreadcrumbBlock)