1 |
efrain |
1 |
// Copyright 2019 Google
|
|
|
2 |
//
|
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
|
5 |
// You may obtain a copy of the License at
|
|
|
6 |
//
|
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
//
|
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
// See the License for the specific language governing permissions and
|
|
|
13 |
// limitations under the License.
|
|
|
14 |
|
|
|
15 |
#import <Foundation/Foundation.h>
|
|
|
16 |
|
|
|
17 |
#import "FIRCrashlyticsReport.h"
|
|
|
18 |
#import "FIRExceptionModel.h"
|
|
|
19 |
|
|
|
20 |
#if __has_include(<Crashlytics/Crashlytics.h>)
|
|
|
21 |
#warning "FirebaseCrashlytics and Crashlytics are not compatible \
|
|
|
22 |
in the same app because including multiple crash reporters can \
|
|
|
23 |
cause problems when registering exception handlers."
|
|
|
24 |
#endif
|
|
|
25 |
|
|
|
26 |
NS_ASSUME_NONNULL_BEGIN
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* The Firebase Crashlytics API provides methods to annotate and manage fatal and
|
|
|
30 |
* non-fatal reports captured and reported to Firebase Crashlytics.
|
|
|
31 |
*
|
|
|
32 |
* By default, Firebase Crashlytics is initialized with FirebaseApp.configure().
|
|
|
33 |
*
|
|
|
34 |
* Note: The Crashlytics class cannot be subclassed. If this makes testing difficult,
|
|
|
35 |
* we suggest using a wrapper class or a protocol extension.
|
|
|
36 |
*/
|
|
|
37 |
NS_SWIFT_NAME(Crashlytics)
|
|
|
38 |
@interface FIRCrashlytics : NSObject
|
|
|
39 |
|
|
|
40 |
/** :nodoc: */
|
|
|
41 |
- (instancetype)init NS_UNAVAILABLE;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Accesses the singleton Crashlytics instance.
|
|
|
45 |
*
|
|
|
46 |
* @return The singleton Crashlytics instance.
|
|
|
47 |
*/
|
|
|
48 |
+ (instancetype)crashlytics NS_SWIFT_NAME(crashlytics());
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Adds logging that is sent with your crash data. The logging does not appear in the
|
|
|
52 |
* system.log and is only visible in the Crashlytics dashboard.
|
|
|
53 |
*
|
|
|
54 |
* @param msg Message to log
|
|
|
55 |
*/
|
|
|
56 |
- (void)log:(NSString *)msg;
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Adds logging that is sent with your crash data. The logging does not appear in the
|
|
|
60 |
* system.log and is only visible in the Crashlytics dashboard.
|
|
|
61 |
*
|
|
|
62 |
* @param format Format of string
|
|
|
63 |
* @param ... A comma-separated list of arguments to substitute into format
|
|
|
64 |
*/
|
|
|
65 |
- (void)logWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2);
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Adds logging that is sent with your crash data. The logging does not appear in the
|
|
|
69 |
* system.log and is only visible in the Crashlytics dashboard.
|
|
|
70 |
*
|
|
|
71 |
* @param format Format of string
|
|
|
72 |
* @param args Arguments to substitute into format
|
|
|
73 |
*/
|
|
|
74 |
- (void)logWithFormat:(NSString *)format
|
|
|
75 |
arguments:(va_list)args NS_SWIFT_NAME(log(format:arguments:));
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Sets a custom key and value to be associated with subsequent fatal and non-fatal reports.
|
|
|
79 |
* When setting an object value, the object is converted to a string. This is
|
|
|
80 |
* typically done by using the object's `description`.
|
|
|
81 |
*
|
|
|
82 |
* @param value The value to be associated with the key
|
|
|
83 |
* @param key A unique key
|
|
|
84 |
*/
|
|
|
85 |
- (void)setCustomValue:(nullable id)value forKey:(NSString *)key;
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Sets custom keys and values to be associated with subsequent fatal and non-fatal reports.
|
|
|
89 |
* The objects in the dictionary are converted to strings. This is
|
|
|
90 |
* typically done by using the object's `description`.
|
|
|
91 |
*
|
|
|
92 |
* @param keysAndValues The values to be associated with the corresponding keys
|
|
|
93 |
*/
|
|
|
94 |
- (void)setCustomKeysAndValues:(NSDictionary *)keysAndValues;
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Records a user ID (identifier) that's associated with subsequent fatal and non-fatal reports.
|
|
|
98 |
*
|
|
|
99 |
* If you want to associate a crash with a specific user, we recommend specifying an arbitrary
|
|
|
100 |
* string (e.g., a database, ID, hash, or other value that you can index and query, but is
|
|
|
101 |
* meaningless to a third-party observer). This allows you to facilitate responses for support
|
|
|
102 |
* requests and reach out to users for more information.
|
|
|
103 |
*
|
|
|
104 |
* @param userID An arbitrary user identifier string that associates a user to a record in your
|
|
|
105 |
* system.
|
|
|
106 |
*/
|
|
|
107 |
- (void)setUserID:(nullable NSString *)userID;
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Records a non-fatal event described by an Error object. The events are
|
|
|
111 |
* grouped and displayed similarly to crashes. Keep in mind that this method can be expensive.
|
|
|
112 |
* The total number of Errors that can be recorded during your app's life-cycle is limited by a
|
|
|
113 |
* fixed-size circular buffer. If the buffer is overrun, the oldest data is dropped. Errors are
|
|
|
114 |
* relayed to Crashlytics on a subsequent launch of your application.
|
|
|
115 |
*
|
|
|
116 |
* @param error Non-fatal error to be recorded
|
|
|
117 |
*/
|
|
|
118 |
- (void)recordError:(NSError *)error NS_SWIFT_NAME(record(error:));
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* Records an Exception Model described by an ExceptionModel object. The events are
|
|
|
122 |
* grouped and displayed similarly to crashes. Keep in mind that this method can be expensive.
|
|
|
123 |
* The total number of ExceptionModels that can be recorded during your app's life-cycle is
|
|
|
124 |
* limited by a fixed-size circular buffer. If the buffer is overrun, the oldest data is dropped.
|
|
|
125 |
* ExceptionModels are relayed to Crashlytics on a subsequent launch of your application.
|
|
|
126 |
*
|
|
|
127 |
* @param exceptionModel Instance of the ExceptionModel to be recorded
|
|
|
128 |
*/
|
|
|
129 |
- (void)recordExceptionModel:(FIRExceptionModel *)exceptionModel
|
|
|
130 |
NS_SWIFT_NAME(record(exceptionModel:));
|
|
|
131 |
|
|
|
132 |
/**
|
|
|
133 |
* Returns whether the app crashed during the previous execution.
|
|
|
134 |
*/
|
|
|
135 |
- (BOOL)didCrashDuringPreviousExecution;
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* Enables/disables automatic data collection.
|
|
|
139 |
*
|
|
|
140 |
* Calling this method overrides both the FirebaseCrashlyticsCollectionEnabled flag in your
|
|
|
141 |
* App's Info.plist and FirebaseApp's isDataCollectionDefaultEnabled flag.
|
|
|
142 |
*
|
|
|
143 |
* When you set a value for this method, it persists across runs of the app.
|
|
|
144 |
*
|
|
|
145 |
* The value does not apply until the next run of the app. If you want to disable data
|
|
|
146 |
* collection without rebooting, add the FirebaseCrashlyticsCollectionEnabled flag to your app's
|
|
|
147 |
* Info.plist.
|
|
|
148 |
* *
|
|
|
149 |
* @param enabled Determines whether automatic data collection is enabled
|
|
|
150 |
*/
|
|
|
151 |
- (void)setCrashlyticsCollectionEnabled:(BOOL)enabled;
|
|
|
152 |
|
|
|
153 |
/**
|
|
|
154 |
* Indicates whether or not automatic data collection is enabled
|
|
|
155 |
*
|
|
|
156 |
* This method uses three ways to decide whether automatic data collection is enabled,
|
|
|
157 |
* in order of priority:
|
|
|
158 |
* - If setCrashlyticsCollectionEnabled is called with a value, use it
|
|
|
159 |
* - If the FirebaseCrashlyticsCollectionEnabled key is in your app's Info.plist, use it
|
|
|
160 |
* - Otherwise, use the default isDataCollectionDefaultEnabled in FirebaseApp
|
|
|
161 |
*/
|
|
|
162 |
- (BOOL)isCrashlyticsCollectionEnabled;
|
|
|
163 |
|
|
|
164 |
/**
|
|
|
165 |
* Determines whether there are any unsent crash reports cached on the device, then calls the given
|
|
|
166 |
* callback.
|
|
|
167 |
*
|
|
|
168 |
* The callback only executes if automatic data collection is disabled. You can use
|
|
|
169 |
* the callback to get one-time consent from a user upon a crash, and then call
|
|
|
170 |
* sendUnsentReports or deleteUnsentReports, depending on whether or not the user gives consent.
|
|
|
171 |
*
|
|
|
172 |
* Disable automatic collection by:
|
|
|
173 |
* - Adding the FirebaseCrashlyticsCollectionEnabled: NO key to your App's Info.plist
|
|
|
174 |
* - Calling `FirebaseCrashlytics.crashlytics().setCrashlyticsCollectionEnabled(false)` in your app
|
|
|
175 |
* - Setting FirebaseApp's isDataCollectionDefaultEnabled to false
|
|
|
176 |
*
|
|
|
177 |
* @param completion The callback that's executed once Crashlytics finishes checking for unsent
|
|
|
178 |
* reports. The callback is set to true if there are unsent reports on disk.
|
|
|
179 |
*/
|
|
|
180 |
- (void)checkForUnsentReportsWithCompletion:(void (^)(BOOL))completion
|
|
|
181 |
NS_SWIFT_NAME(checkForUnsentReports(completion:));
|
|
|
182 |
|
|
|
183 |
/**
|
|
|
184 |
* Determines whether there are any unsent crash reports cached on the device, then calls the given
|
|
|
185 |
* callback with a CrashlyticsReport object that you can use to update the unsent report.
|
|
|
186 |
* CrashlyticsReports have a lot of the familiar Crashlytics methods like setting custom keys and
|
|
|
187 |
* logs.
|
|
|
188 |
*
|
|
|
189 |
* The callback only executes if automatic data collection is disabled. You can use
|
|
|
190 |
* the callback to get one-time consent from a user upon a crash, and then call
|
|
|
191 |
* sendUnsentReports or deleteUnsentReports, depending on whether or not the user gives consent.
|
|
|
192 |
*
|
|
|
193 |
* Disable automatic collection by:
|
|
|
194 |
* - Adding the FirebaseCrashlyticsCollectionEnabled: NO key to your App's Info.plist
|
|
|
195 |
* - Calling `FirebaseCrashlytics.crashlytics().setCrashlyticsCollectionEnabled(false)` in your app
|
|
|
196 |
* - Setting FirebaseApp's isDataCollectionDefaultEnabled to false
|
|
|
197 |
*
|
|
|
198 |
* Not calling send/deleteUnsentReports will result in the report staying on disk, which means the
|
|
|
199 |
* same CrashlyticsReport can show up in multiple runs of the app. If you want avoid duplicates,
|
|
|
200 |
* ensure there was a crash on the last run of the app by checking the value of
|
|
|
201 |
* didCrashDuringPreviousExecution.
|
|
|
202 |
*
|
|
|
203 |
* @param completion The callback that's executed once Crashlytics finishes checking for unsent
|
|
|
204 |
* reports. The callback is called with the newest unsent Crashlytics Report, or nil if there are
|
|
|
205 |
* none cached on disk.
|
|
|
206 |
*/
|
|
|
207 |
- (void)checkAndUpdateUnsentReportsWithCompletion:
|
|
|
208 |
(void (^)(FIRCrashlyticsReport *_Nullable))completion
|
|
|
209 |
NS_SWIFT_NAME(checkAndUpdateUnsentReports(completion:));
|
|
|
210 |
|
|
|
211 |
/**
|
|
|
212 |
* Enqueues any unsent reports on the device to upload to Crashlytics.
|
|
|
213 |
*
|
|
|
214 |
* This method only applies if automatic data collection is disabled.
|
|
|
215 |
*
|
|
|
216 |
* When automatic data collection is enabled, Crashlytics automatically uploads and deletes reports
|
|
|
217 |
* at startup, so this method is ignored.
|
|
|
218 |
*/
|
|
|
219 |
- (void)sendUnsentReports;
|
|
|
220 |
|
|
|
221 |
/**
|
|
|
222 |
* Deletes any unsent reports on the device.
|
|
|
223 |
*
|
|
|
224 |
* This method only applies if automatic data collection is disabled.
|
|
|
225 |
*/
|
|
|
226 |
- (void)deleteUnsentReports;
|
|
|
227 |
|
|
|
228 |
@end
|
|
|
229 |
|
|
|
230 |
NS_ASSUME_NONNULL_END
|