forked from Countly/countly-sdk-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Countly.h
executable file
·362 lines (295 loc) · 15.5 KB
/
Countly.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
// Countly.h
//
// This code is provided under the MIT License.
//
// Please visit www.count.ly for more information.
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import "CountlyUserDetails.h"
#import "CountlyConfig.h"
#if TARGET_OS_IOS
#import <UserNotifications/UserNotifications.h>
#endif
NS_ASSUME_NONNULL_BEGIN
@interface Countly : NSObject
#pragma mark - Countly Core
/**
* Returns @c Countly singleton to be used throughout the app.
* @return The shared @c Countly object
*/
+ (instancetype)sharedInstance;
/**
* Starts Countly with given configuration and begins session.
* @param config @c CountlyConfig object that defines host, app key, optional features and other settings
*/
- (void)startWithConfig:(CountlyConfig *)config;
/**
* Sets new device ID to be persistently stored and used in following requests.
* @param deviceID New device ID
* @param onServer If set, data on Countly Server will be merged automatically, otherwise device will be counted as a new device
*/
- (void)setNewDeviceID:(NSString * _Nullable)deviceID onServer:(BOOL)onServer;
/**
* Sets the value of the custom HTTP header field to be sent with every request if @c customHeaderFieldName is set on initial configuration.
* @discussion If @c customHeaderFieldValue on initial configuration can not be set on app launch, this method can be used to do so later. Requests not started due to missing @c customHeaderFieldValue since app launch will start hereafter.
* @param customHeaderFieldValue Custom header field value
*/
- (void)setCustomHeaderFieldValue:(NSString *)customHeaderFieldValue;
/**
* Starts session and sends @c begin_session request with default metrics for manual session handling.
* @discussion This method needs to be called for starting a session only if @c manualSessionHandling flag is set on initial configuration. Otherwise; sessions will be handled automatically by default, and calling this method will have no effect.
*/
- (void)beginSession;
/**
* Updates session and sends unsent session duration for manual session handling.
* @discussion This method needs to be called for updating a session only if @c manualSessionHandling flag is set on initial configuration. Otherwise; sessions will be handled automatically by default, and calling this method will have no effect.
*/
- (void)updateSession;
/**
* Ends session and sends @c end_session request for manual session handling.
* @discussion This method needs to be called for ending a session only if @c manualSessionHandling flag is set on initial configuration. Otherwise; sessions will be handled automatically by default, and calling this method will have no effect.
*/
- (void)endSession;
#if TARGET_OS_WATCH
/**
* Suspends Countly, adds recorded events to request queue and ends current session.
* @discussion This method needs to be called manually only on @c watchOS, on other platforms it will be called automatically.
*/
- (void)suspend;
/**
* Resumes Countly, begins a new session after the app comes to foreground.
* @discussion This method needs to be called manually only on @c watchOS, on other platforms it will be called automatically.
*/
- (void)resume;
#endif
#pragma mark - Countly CustomEvents
/**
* Records event with given key.
* @param key Event key
*/
- (void)recordEvent:(NSString *)key;
/**
* Records event with given key and count.
* @param key Event key
* @param count Count of event occurrences
*/
- (void)recordEvent:(NSString *)key count:(NSUInteger)count;
/**
* Records event with given key and sum.
* @param key Event key
* @param sum Sum of any specific value for event
*/
- (void)recordEvent:(NSString *)key sum:(double)sum;
/**
* Records event with given key and duration.
* @param key Event key
* @param duration Duration of event in seconds
*/
- (void)recordEvent:(NSString *)key duration:(NSTimeInterval)duration;
/**
* Records event with given key, count and sum.
* @param key Event key
* @param count Count of event occurrences
* @param sum Sum of any specific value for event
*/
- (void)recordEvent:(NSString *)key count:(NSUInteger)count sum:(double)sum;
/**
* Records event with given key and segmentation.
* @param key Event key
* @param segmentation Segmentation key-value pairs of event
*/
- (void)recordEvent:(NSString *)key segmentation:(NSDictionary * _Nullable)segmentation;
/**
* Records event with given key, segmentation and count.
* @param key Event key
* @param segmentation Segmentation key-value pairs of event
* @param count Count of event occurrences
*/
- (void)recordEvent:(NSString *)key segmentation:(NSDictionary * _Nullable)segmentation count:(NSUInteger)count;
/**
* Records event with given key, segmentation, count and sum.
* @param key Event key
* @param segmentation Segmentation key-value pairs of event
* @param count Count of event occurrences
* @param sum Sum of any specific value for event
*/
- (void)recordEvent:(NSString *)key segmentation:(NSDictionary * _Nullable)segmentation count:(NSUInteger)count sum:(double)sum;
/**
* Records event with given key, segmentation, count, sum and duration.
* @param key Event key
* @param segmentation Segmentation key-value pairs of event
* @param count Count of event occurrences
* @param sum Sum of any specific value for event
* @param duration Duration of event in seconds
*/
- (void)recordEvent:(NSString *)key segmentation:(NSDictionary * _Nullable)segmentation count:(NSUInteger)count sum:(double)sum duration:(NSTimeInterval)duration;
/**
* Starts a timed event with given key to be ended later. Duration of timed event will be calculated on ending.
* @discussion Trying to start an event with already started key will have no effect.
* @param key Event key
*/
- (void)startEvent:(NSString *)key;
/**
* Ends a previously started timed event with given key.
* @discussion Trying to end an event with already ended (or not yet started) key will have no effect.
* @param key Event key
*/
- (void)endEvent:(NSString *)key;
/**
* Ends a previously started timed event with given key, segmentation, count and sum.
* @discussion Trying to end an event with already ended (or not yet started) key will have no effect.
* @param key Event key
* @param segmentation Segmentation key-value pairs of event
* @param count Count of event occurrences
* @param sum Sum of any specific value for event
*/
- (void)endEvent:(NSString *)key segmentation:(NSDictionary * _Nullable)segmentation count:(NSUInteger)count sum:(double)sum;
#pragma mark - Countly PushNotifications
#if TARGET_OS_IOS
/**
* Shows default system dialog that asks for user's permission to display notifications.
* @discussion A unified convenience method that handles asking for notification permission on both iOS10 and older iOS versions with badge, sound and alert notification types.
*/
- (void)askForNotificationPermission;
/**
* Shows default system dialog that asks for user's permission to display notifications with given options and completion handler.
* @discussion A more customizable version of unified convenience method that handles asking for notification permission on both iOS10 and older iOS versions.
* @discussion Notification types the app wants to display can be specified using @c options parameter.
* @discussion Completion block has a @c BOOL parameter named @c granted which is @c YES if user granted permission, and an @c NSError parameter named @c error which indicates if there is an error.
* @param options Bitwise combination of notification types (badge, sound or alert) the app wants to display
* @param completionHandler A completion handler block to be executed when user answers notification permission dialog
*/
- (void)askForNotificationPermissionWithOptions:(UNAuthorizationOptions)options completionHandler:(void (^)(BOOL granted, NSError * error))completionHandler;
/**
* Records user's location to be used for geo-location based push notifications and advanced segmentation.
* @discussion By default, Countly Server uses a geo-ip database for acquiring user's location. If the app uses Core Location services and granted permission, a location with better accuracy can be provided using this method.
* @discussion Calling this method once or twice per app life is enough, instead of on each location update.
* @discussion This method also overrides @c location property specified on initial configuration, in addition to sending an immediate request.
* @param coordinate User's location with latitude and longitude
*/
- (void)recordLocation:(CLLocationCoordinate2D)coordinate;
/**
* Records user's city and/or ISO country code to be used for geo-location based push notifications and advanced segmentation.
* @discussion By default, Countly Server uses a geo-ip database for acquiring user's location. If the app has information about user's city and/or country, this information can be provided using this method.
* @discussion This method also overrides @c city and @c ISOCountryCode properties specified on initial configuration, in addition to sending an immediate request.
* @param city User's city
* @param ISOCountryCode User's ISO country code in ISO 3166-1 alpha-2 format
*/
- (void)recordCity:(NSString *)city andISOCountryCode:(NSString *)ISOCountryCode;
/**
* Records user's explicit IP address to be used for geo-location based push notifications and advanced segmentation.
* @discussion By default, Countly Server uses a geo-ip database for acquiring user's location, and deduces the IP address from the connection. If the app needs to explicitly specify the IP address due to network requirements, it can be provided using this method.
* @discussion This method only overrides @c IP property specified on initial configuration, without sending an immediate request.
* @param IP User's explicit IP address
*/
- (void)recordIP:(NSString *)IP;
/**
* Records action event for a manually presented push notification with custom action buttons.
* @discussion If a push notification with custom action buttons is handled and presented manually using custom UI, user's action needs to be reported manually. With this convenience method user's action can be reported passing push notification dictionary and clicked button index.
* @discussion Button index should be @c 0 for default action, @c 1 for the first action button and @c 2 for the second action button.
* @param userInfo Manually presented push notification dictionary
* @param buttonIndex Index of custom action button user clicked
*/
- (void)recordActionForNotification:(NSDictionary *)userInfo clickedButtonIndex:(NSInteger)buttonIndex;
/**
* Enables or disables geo-location based push notifications.
* @discussion By default, it is enabled if PushNotifications feature is activated on initial configuration.
* @discussion Changes to this property is persistently stored, and will be effective even after app re-launch.
*/
@property (nonatomic) BOOL isGeoLocationEnabled;
#endif
#pragma mark - Countly CrashReporting
#if TARGET_OS_IOS
/**
* Records a handled exception manually.
* @param exception Exception to be reported
*/
- (void)recordHandledException:(NSException *)exception;
/**
* Records a handled exception and given stack trace manually.
* @param exception Exception to be reported
* @param stackTrace Stack trace to be reported
*/
- (void)recordHandledException:(NSException *)exception withStackTrace:(NSArray * _Nullable)stackTrace;
/**
* Records custom logs to be delivered with crash report.
* @discussion Logs recorded by this method are stored in a non-persistent structure, and delivered to Countly Server only in case of a crash.
* @param log Custom log string to be recorded
*/
- (void)recordCrashLog:(NSString *)log;
/**
* @c crashLog: method is deprecated. Please use @c recordCrashLog: method instead.
* @discussion While @c crashLog: method's parameter type is string format, new @c recordCrashLog: method's parameter type is plain NSString for better Swift compatibility. Please update your code accordingly.
* @discussion Calls to @c crashLog: method will have no effect.
*/
- (void)crashLog:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2) DEPRECATED_MSG_ATTRIBUTE("Use 'recordCrashLog:' method instead!");
#endif
#pragma mark - Countly APM
/**
* Adds exception URL for APM.
* @discussion Added URLs (with or without specific path) will be ignored by APM.
* @discussion Adding an already added URL again will have no effect.
* @param exceptionURL Exception URL to be added
*/
- (void)addExceptionForAPM:(NSString *)exceptionURL;
/**
* Removes exception URL for APM.
* @discussion Removing an already removed (or not yet added) URL again will have no effect.
* @param exceptionURL Exception URL to be removed
*/
- (void)removeExceptionForAPM:(NSString *)exceptionURL;
#pragma mark - Countly AutoViewTracking
/**
* Reports a visited view with given name manually.
* @discussion If AutoViewTracking feature is activated on initial configuration, this method does not need to be called manually.
* @param viewName Name of the view visited
*/
- (void)reportView:(NSString *)viewName;
#if TARGET_OS_IOS
/**
* Adds exception for AutoViewTracking.
* @discussion @c UIViewControllers with specified title or class name will be ignored by AutoViewTracking and their appearances and disappearances will not be reported.
* @discussion Adding an already added @c UIViewController title or subclass name again will have no effect.
* @param exception @c UIViewController title or subclass name to be added as exception
*/
- (void)addExceptionForAutoViewTracking:(NSString *)exception;
/**
* Removes exception for AutoViewTracking.
* @discussion Removing an already removed (or not yet added) @c UIViewController title or subclass name will have no effect.
* @param exception @c UIViewController title or subclass name to be removed
*/
- (void)removeExceptionForAutoViewTracking:(NSString *)exception;
/**
* Enables or disables AutoViewTracking, if AutoViewTracking feature is activated on start configuration.
* @discussion If AutoViewTracking feature is not activated on start configuration, this property has no effect on enabling or disabling it later.
*/
@property (nonatomic) BOOL isAutoViewTrackingEnabled;
#endif
#pragma mark - Countly UserDetails
/**
* Returns @c CountlyUserDetails singleton to be used throughout the app.
* @return The shared @c CountlyUserDetails object
*/
+ (CountlyUserDetails *)user;
/**
* Handles switching from device ID to custom user ID for logged in users
* @discussion When a user logs in, this user can be tracked with custom user ID instead of device ID. This is just a convenience method that handles setting user ID as new device ID and merging existing data on Countly Server.
* @param userID Custom user ID uniquely defining the logged in user
*/
- (void)userLoggedIn:(NSString *)userID;
/**
* Handles switching from custom user ID to device ID for logged out users
* @discussion When a user logs out, all the data can be tracked with default device ID henceforth. This is just a convenience method that handles resetting device ID to default one and starting a new session.
*/
- (void)userLoggedOut;
#pragma mark - Countly StarRating
#if TARGET_OS_IOS
/**
* Shows star-rating dialog manually and executes completion block after user's action.
* @discussion Completion block has a single NSInteger parameter that indicates 1 to 5 star-rating given by user. If user dismissed dialog without giving a rating, this value will be 0 and it will not be reported to Countly Server.
* @param completion A block object to be executed when user gives a star-rating or dismisses dialog without rating
*/
- (void)askForStarRating:(void(^)(NSInteger rating))completion;
#endif
NS_ASSUME_NONNULL_END
@end