Crashlytics

@interface Crashlytics : NSObject

Crashlytics. Handles configuration and initialization of Crashlytics.

Note: The Crashlytics class cannot be subclassed. If this is causing you pain for testing, we suggest using either a wrapper class or a protocol extension.

  • The delegate can be used to influence decisions on reporting and behavior, as well as reacting to previous crashes.

    Make certain that the delegate is setup before starting Crashlytics with startWithAPIKey:… or via +[Fabric with:…]. Failure to do will result in missing any delegate callbacks that occur synchronously during start.

    Declaration

    Swift

    unowned(unsafe) var delegate: AnyObject? { get set }

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) id delegate;
  • The recommended way to install Crashlytics into your application is to place a call to +startWithAPIKey: in your -application:didFinishLaunchingWithOptions: or -applicationDidFinishLaunching: method.

    Note: Starting with 3.0, the submission process has been significantly improved. The delay parameter is no longer required to throttle submissions on launch, performance will be great without it.

    Declaration

    Swift

    class func start(withAPIKey apiKey: String) -> Crashlytics

    Objective-C

    + (nonnull Crashlytics *)startWithAPIKey:(nonnull NSString *)apiKey;

    Parameters

    apiKey

    The Crashlytics API Key for this app

    Return Value

    The singleton Crashlytics instance

  • If you need the functionality provided by the CrashlyticsDelegate protocol, you can use these convenience methods to activate the framework and set the delegate in one call.

    Declaration

    Swift

    class func start(withAPIKey apiKey: String, delegate: Any?) -> Crashlytics

    Objective-C

    + (nonnull Crashlytics *)startWithAPIKey:(nonnull NSString *)apiKey
                                    delegate:(nullable id)delegate;

    Parameters

    apiKey

    The Crashlytics API Key for this app

    delegate

    A delegate object which conforms to CrashlyticsDelegate.

    Return Value

    The singleton Crashlytics instance

  • Access the singleton Crashlytics instance.

    Declaration

    Swift

    class func sharedInstance() -> Crashlytics

    Objective-C

    + (nonnull Crashlytics *)sharedInstance;

    Return Value

    The singleton Crashlytics instance

  • The easiest way to cause a crash - great for testing!

    Declaration

    Swift

    func crash()

    Objective-C

    - (void)crash;
  • The easiest way to cause a crash with an exception - great for testing.

    Declaration

    Swift

    func throwException()

    Objective-C

    - (void)throwException;
  • Specify a user identifier which will be visible in the Crashlytics UI.

    Many of our customers have requested the ability to tie crashes to specific end-users of their application in order to facilitate responses to support requests or permit the ability to reach out for more information. We allow you to specify up to three separate values for display within the Crashlytics UI - but please be mindful of your end-user’s privacy.

    We recommend specifying a user identifier - an arbitrary string that ties an end-user to a record in your system. This could be a database id, hash, or other value that is meaningless to a third-party observer but can be indexed and queried by you.

    Optionally, you may also specify the end-user’s name or username, as well as email address if you do not have a system that works well with obscured identifiers.

    Pursuant to our EULA, this data is transferred securely throughout our system and we will not disseminate end-user data unless required to by law. That said, if you choose to provide end-user contact information, we strongly recommend that you disclose this in your application’s privacy policy. Data privacy is of our utmost concern.

    Declaration

    Swift

    func setUserIdentifier(_ identifier: String?)

    Objective-C

    - (void)setUserIdentifier:(nullable NSString *)identifier;

    Parameters

    identifier

    An arbitrary user identifier string which ties an end-user to a record in your system.

  • Specify a user name which will be visible in the Crashlytics UI. Please be mindful of your end-user’s privacy and see if setUserIdentifier: can fulfil your needs.

    See

    setUserIdentifier:

    Declaration

    Swift

    func setUserName(_ name: String?)

    Objective-C

    - (void)setUserName:(nullable NSString *)name;

    Parameters

    name

    An end user’s name.

  • Specify a user email which will be visible in the Crashlytics UI. Please be mindful of your end-user’s privacy and see if setUserIdentifier: can fulfil your needs.

    See

    setUserIdentifier:

    Declaration

    Swift

    func setUserEmail(_ email: String?)

    Objective-C

    - (void)setUserEmail:(nullable NSString *)email;

    Parameters

    email

    An end user’s email address.

  • Set a value for a for a key to be associated with your crash data which will be visible in the Crashlytics UI. When setting an object value, the object is converted to a string. This is typically done by calling -[NSObject description].

    Declaration

    Swift

    func setObjectValue(_ value: Any?, forKey key: String)

    Objective-C

    - (void)setObjectValue:(nullable id)value forKey:(nonnull NSString *)key;

    Parameters

    value

    The object to be associated with the key

    key

    The key with which to associate the value

  • Set an int value for a key to be associated with your crash data which will be visible in the Crashlytics UI.

    Declaration

    Swift

    func setIntValue(_ value: Int32, forKey key: String)

    Objective-C

    - (void)setIntValue:(int)value forKey:(nonnull NSString *)key;

    Parameters

    value

    The integer value to be set

    key

    The key with which to associate the value

  • Set an BOOL value for a key to be associated with your crash data which will be visible in the Crashlytics UI.

    Declaration

    Swift

    func setBoolValue(_ value: Bool, forKey key: String)

    Objective-C

    - (void)setBoolValue:(BOOL)value forKey:(nonnull NSString *)key;

    Parameters

    value

    The BOOL value to be set

    key

    The key with which to associate the value

  • Set an float value for a key to be associated with your crash data which will be visible in the Crashlytics UI.

    Declaration

    Swift

    func setFloatValue(_ value: Float, forKey key: String)

    Objective-C

    - (void)setFloatValue:(float)value forKey:(nonnull NSString *)key;

    Parameters

    value

    The float value to be set

    key

    The key with which to associate the value

  • This method can be used to record a single exception structure in a report. This is particularly useful when your code interacts with non-native languages like Lua, C#, or Javascript. This call can be expensive and should only be used shortly before process termination. This API is not intended be to used to log NSException objects. All safely-reportable NSExceptions are automatically captured by Crashlytics.

    Declaration

    Swift

    func recordCustomExceptionName(_ name: String, reason: String?, frameArray: [Any])

    Objective-C

    - (void)recordCustomExceptionName:(nonnull NSString *)name
                               reason:(nullable NSString *)reason
                           frameArray:(nonnull NSArray *)frameArray;

    Parameters

    name

    The name of the custom exception

    reason

    The reason this exception occurred

    frameArray

    An array of CLSStackFrame objects

  • This allows you to record a non-fatal event, described by an NSError object. These events will be grouped and displayed similarly to crashes. Keep in mind that this method can be expensive. Also, the total number of NSErrors that can be recorded during your app’s life-cycle is limited by a fixed-size circular buffer. If the buffer is overrun, the oldest data is dropped. Errors are relayed to Crashlytics on a subsequent launch of your application.

    You can also use the -recordError:withAdditionalUserInfo: to include additional context not represented by the NSError instance itself.

    Declaration

    Swift

    func recordError(_ error: Error)

    Objective-C

    - (void)recordError:(nonnull NSError *)error;