You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

288 lines
13 KiB

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