5 // Copyright (c) 2015 Crashlytics, Inc. All rights reserved.
8 #import <Foundation/Foundation.h>
10 #import "CLSAttributes.h"
11 #import "CLSLogging.h"
13 #import "CLSStackFrame.h"
16 NS_ASSUME_NONNULL_BEGIN
18 @protocol CrashlyticsDelegate;
21 * Crashlytics. Handles configuration and initialization of Crashlytics.
23 * Note: The Crashlytics class cannot be subclassed. If this is causing you pain for
24 * testing, we suggest using either a wrapper class or a protocol extension.
26 @interface Crashlytics : NSObject
28 @property (nonatomic, readonly, copy) NSString *APIKey;
29 @property (nonatomic, readonly, copy) NSString *version;
30 @property (nonatomic, assign) BOOL debugMode;
34 * The delegate can be used to influence decisions on reporting and behavior, as well as reacting
35 * to previous crashes.
37 * Make certain that the delegate is setup before starting Crashlytics with startWithAPIKey:... or
38 * via +[Fabric with:...]. Failure to do will result in missing any delegate callbacks that occur
39 * synchronously during start.
42 @property (nonatomic, assign, nullable) id <CrashlyticsDelegate> delegate;
45 * The recommended way to install Crashlytics into your application is to place a call to +startWithAPIKey:
46 * in your -application:didFinishLaunchingWithOptions: or -applicationDidFinishLaunching:
49 * Note: Starting with 3.0, the submission process has been significantly improved. The delay parameter
50 * is no longer required to throttle submissions on launch, performance will be great without it.
52 * @param apiKey The Crashlytics API Key for this app
54 * @return The singleton Crashlytics instance
56 + (Crashlytics *)startWithAPIKey:(NSString *)apiKey;
57 + (Crashlytics *)startWithAPIKey:(NSString *)apiKey afterDelay:(NSTimeInterval)delay CLS_DEPRECATED("Crashlytics no longer needs or uses the delay parameter. Please use +startWithAPIKey: instead.");
60 * If you need the functionality provided by the CrashlyticsDelegate protocol, you can use
61 * these convenience methods to activate the framework and set the delegate in one call.
63 * @param apiKey The Crashlytics API Key for this app
64 * @param delegate A delegate object which conforms to CrashlyticsDelegate.
66 * @return The singleton Crashlytics instance
68 + (Crashlytics *)startWithAPIKey:(NSString *)apiKey delegate:(nullable id<CrashlyticsDelegate>)delegate;
69 + (Crashlytics *)startWithAPIKey:(NSString *)apiKey delegate:(nullable id<CrashlyticsDelegate>)delegate afterDelay:(NSTimeInterval)delay CLS_DEPRECATED("Crashlytics no longer needs or uses the delay parameter. Please use +startWithAPIKey:delegate: instead.");
72 * Access the singleton Crashlytics instance.
74 * @return The singleton Crashlytics instance
76 + (Crashlytics *)sharedInstance;
79 * The easiest way to cause a crash - great for testing!
84 * The easiest way to cause a crash with an exception - great for testing.
86 - (void)throwException;
89 * Specify a user identifier which will be visible in the Crashlytics UI.
91 * Many of our customers have requested the ability to tie crashes to specific end-users of their
92 * application in order to facilitate responses to support requests or permit the ability to reach
93 * out for more information. We allow you to specify up to three separate values for display within
94 * the Crashlytics UI - but please be mindful of your end-user's privacy.
96 * We recommend specifying a user identifier - an arbitrary string that ties an end-user to a record
97 * in your system. This could be a database id, hash, or other value that is meaningless to a
98 * third-party observer but can be indexed and queried by you.
100 * Optionally, you may also specify the end-user's name or username, as well as email address if you
101 * do not have a system that works well with obscured identifiers.
103 * Pursuant to our EULA, this data is transferred securely throughout our system and we will not
104 * disseminate end-user data unless required to by law. That said, if you choose to provide end-user
105 * contact information, we strongly recommend that you disclose this in your application's privacy
106 * policy. Data privacy is of our utmost concern.
108 * @param identifier An arbitrary user identifier string which ties an end-user to a record in your system.
110 - (void)setUserIdentifier:(nullable NSString *)identifier;
113 * Specify a user name which will be visible in the Crashlytics UI.
114 * Please be mindful of your end-user's privacy and see if setUserIdentifier: can fulfil your needs.
115 * @see setUserIdentifier:
117 * @param name An end user's name.
119 - (void)setUserName:(nullable NSString *)name;
122 * Specify a user email which will be visible in the Crashlytics UI.
123 * Please be mindful of your end-user's privacy and see if setUserIdentifier: can fulfil your needs.
125 * @see setUserIdentifier:
127 * @param email An end user's email address.
129 - (void)setUserEmail:(nullable NSString *)email;
131 + (void)setUserIdentifier:(nullable NSString *)identifier CLS_DEPRECATED("Please access this method via +sharedInstance");
132 + (void)setUserName:(nullable NSString *)name CLS_DEPRECATED("Please access this method via +sharedInstance");
133 + (void)setUserEmail:(nullable NSString *)email CLS_DEPRECATED("Please access this method via +sharedInstance");
136 * Set a value for a for a key to be associated with your crash data which will be visible in the Crashlytics UI.
137 * When setting an object value, the object is converted to a string. This is typically done by calling
138 * -[NSObject description].
140 * @param value The object to be associated with the key
141 * @param key The key with which to associate the value
143 - (void)setObjectValue:(nullable id)value forKey:(NSString *)key;
146 * Set an int value for a key to be associated with your crash data which will be visible in the Crashlytics UI.
148 * @param value The integer value to be set
149 * @param key The key with which to associate the value
151 - (void)setIntValue:(int)value forKey:(NSString *)key;
154 * Set an BOOL value for a key to be associated with your crash data which will be visible in the Crashlytics UI.
156 * @param value The BOOL value to be set
157 * @param key The key with which to associate the value
159 - (void)setBoolValue:(BOOL)value forKey:(NSString *)key;
162 * Set an float value for a key to be associated with your crash data which will be visible in the Crashlytics UI.
164 * @param value The float value to be set
165 * @param key The key with which to associate the value
167 - (void)setFloatValue:(float)value forKey:(NSString *)key;
169 + (void)setObjectValue:(nullable id)value forKey:(NSString *)key CLS_DEPRECATED("Please access this method via +sharedInstance");
170 + (void)setIntValue:(int)value forKey:(NSString *)key CLS_DEPRECATED("Please access this method via +sharedInstance");
171 + (void)setBoolValue:(BOOL)value forKey:(NSString *)key CLS_DEPRECATED("Please access this method via +sharedInstance");
172 + (void)setFloatValue:(float)value forKey:(NSString *)key CLS_DEPRECATED("Please access this method via +sharedInstance");
175 * This method can be used to record a single exception structure in a report. This is particularly useful
176 * when your code interacts with non-native languages like Lua, C#, or Javascript. This call can be
177 * expensive and should only be used shortly before process termination. This API is not intended be to used
178 * to log NSException objects. All safely-reportable NSExceptions are automatically captured by
181 * @param name The name of the custom exception
182 * @param reason The reason this exception occurred
183 * @param frameArray An array of CLSStackFrame objects
185 - (void)recordCustomExceptionName:(NSString *)name reason:(nullable NSString *)reason frameArray:(CLS_GENERIC_NSARRAY(CLSStackFrame *) *)frameArray;
189 * This allows you to record a non-fatal event, described by an NSError object. These events will be grouped and
190 * displayed similarly to crashes. Keep in mind that this method can be expensive. Also, the total number of
191 * NSErrors that can be recorded during your app's life-cycle is limited by a fixed-size circular buffer. If the
192 * buffer is overrun, the oldest data is dropped. Errors are relayed to Crashlytics on a subsequent launch
193 * of your application.
195 * You can also use the -recordError:withAdditionalUserInfo: to include additional context not represented
196 * by the NSError instance itself.
199 - (void)recordError:(NSError *)error;
200 - (void)recordError:(NSError *)error withAdditionalUserInfo:(nullable CLS_GENERIC_NSDICTIONARY(NSString *, id) *)userInfo;
202 - (void)logEvent:(NSString *)eventName CLS_DEPRECATED("Please refer to Answers +logCustomEventWithName:");
203 - (void)logEvent:(NSString *)eventName attributes:(nullable NSDictionary *) attributes CLS_DEPRECATED("Please refer to Answers +logCustomEventWithName:");
204 + (void)logEvent:(NSString *)eventName CLS_DEPRECATED("Please refer to Answers +logCustomEventWithName:");
205 + (void)logEvent:(NSString *)eventName attributes:(nullable NSDictionary *) attributes CLS_DEPRECATED("Please refer to Answers +logCustomEventWithName:");
211 * The CrashlyticsDelegate protocol provides a mechanism for your application to take
212 * action on events that occur in the Crashlytics crash reporting system. You can make
213 * use of these calls by assigning an object to the Crashlytics' delegate property directly,
214 * or through the convenience +startWithAPIKey:delegate: method.
217 @protocol CrashlyticsDelegate <NSObject>
221 - (void)crashlyticsDidDetectCrashDuringPreviousExecution:(Crashlytics *)crashlytics CLS_DEPRECATED("Please refer to -crashlyticsDidDetectReportForLastExecution:");
222 - (void)crashlytics:(Crashlytics *)crashlytics didDetectCrashDuringPreviousExecution:(id <CLSCrashReport>)crash CLS_DEPRECATED("Please refer to -crashlyticsDidDetectReportForLastExecution:");
226 * Called when a Crashlytics instance has determined that the last execution of the
227 * application resulted in a saved report. This is called synchronously on Crashlytics
228 * initialization. Your delegate must invoke the completionHandler, but does not need to do so
229 * synchronously, or even on the main thread. Invoking completionHandler with NO will cause the
230 * detected report to be deleted and not submitted to Crashlytics. This is useful for
231 * implementing permission prompts, or other more-complex forms of logic around submitting crashes.
233 * Instead of using this method, you should try to make use of -crashlyticsDidDetectReportForLastExecution:
236 * @warning Failure to invoke the completionHandler will prevent submissions from being reported. Watch out.
238 * @warning Just implementing this delegate method will disable all forms of synchronous report submission. This can
239 * impact the reliability of reporting crashes very early in application launch.
241 * @param report The CLSReport object representing the last detected report
242 * @param completionHandler The completion handler to call when your logic has completed.
245 - (void)crashlyticsDidDetectReportForLastExecution:(CLSReport *)report completionHandler:(void (^)(BOOL submit))completionHandler;
249 * Called when a Crashlytics instance has determined that the last execution of the
250 * application resulted in a saved report. This method differs from
251 * -crashlyticsDidDetectReportForLastExecution:completionHandler: in three important ways:
253 * - it is not called synchronously during initialization
254 * - it does not give you the ability to prevent the report from being submitted
255 * - the report object itself is immutable
257 * Thanks to these limitations, making use of this method does not impact reporting
258 * reliabilty in any way.
260 * @param report The read-only CLSReport object representing the last detected report
264 - (void)crashlyticsDidDetectReportForLastExecution:(CLSReport *)report;
267 * If your app is running on an OS that supports it (OS X 10.9+, iOS 7.0+), Crashlytics will submit
268 * most reports using out-of-process background networking operations. This results in a significant
269 * improvement in reliability of reporting, as well as power and performance wins for your users.
270 * If you don't want this functionality, you can disable by returning NO from this method.
272 * @warning Background submission is not supported for extensions on iOS or OS X.
274 * @param crashlytics The Crashlytics singleton instance
276 * @return Return NO if you don't want out-of-process background network operations.
279 - (BOOL)crashlyticsCanUseBackgroundSessions:(Crashlytics *)crashlytics;
284 * `CrashlyticsKit` can be used as a parameter to `[Fabric with:@[CrashlyticsKit]];` in Objective-C. In Swift, use Crashlytics.sharedInstance()
286 #define CrashlyticsKit [Crashlytics sharedInstance]
288 NS_ASSUME_NONNULL_END