uqudosdk-react-native 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ios/UqudoId.m ADDED
@@ -0,0 +1,538 @@
1
+ #import "UqudoId.h"
2
+ #import <UqudoSDK/UqudoSDK.h>
3
+ #import "MyTracer.h"
4
+
5
+ @implementation UqudoId
6
+
7
+ MyTracer *tracer;
8
+
9
+ RCT_EXPORT_MODULE()
10
+
11
+ RCT_EXPORT_METHOD(init:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
12
+ tracer = [[MyTracer alloc] init];
13
+ tracer.emitter = self;
14
+ dispatch_async(dispatch_get_main_queue(), ^(void) {
15
+ [[UQBuilderController alloc] initWithTracer:tracer];
16
+ });
17
+ }
18
+
19
+ RCT_EXPORT_METHOD(setLocale:(NSString *)locale resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
20
+ [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:locale, nil]forKey:@"AppleLanguages"];
21
+ [[NSUserDefaults standardUserDefaults] synchronize];
22
+ }
23
+
24
+ RCT_EXPORT_METHOD(enroll:(NSString *)enrollObj resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
25
+ self.promiseResolve = resolve;
26
+ self.promiseReject = reject;
27
+
28
+ @try {
29
+ if (enrollObj != nil && [enrollObj length] > 0) {
30
+ NSData* data = [enrollObj dataUsingEncoding:NSUTF8StringEncoding];
31
+ id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
32
+
33
+ NSString* authorizationToken = json[@"authorizationToken"];
34
+ NSString* nonce = json[@"nonce"];
35
+ NSDictionary* documentList = json[@"documentList"];
36
+ NSDictionary* facialRecognitionSpecification = json[@"facialRecognitionSpecification"];
37
+ NSDictionary* backgroundCheckConfiguration = json[@"backgroundCheckConfiguration"];
38
+ NSDictionary* lookupConfiguration = json[@"lookupConfiguration"];
39
+
40
+ // Config enrollment builder
41
+ UQEnrollmentBuilder *enrollmentBuilder = [[UQEnrollmentBuilder alloc] init];
42
+ NSString* sessionId = json[@"sessionId"];
43
+ if (sessionId && sessionId.length > 0) {
44
+ [enrollmentBuilder setSessionID:sessionId];
45
+ }
46
+ if (json[@"isRootedDeviceAllowed"]) {
47
+ enrollmentBuilder.isRootedDeviceAllowed = [[json valueForKey:@"isRootedDeviceAllowed"] boolValue];
48
+ }
49
+ if (json[@"isReturnDataForIncompleteSession"]) {
50
+ enrollmentBuilder.returnDataForIncompleteSession = [[json valueForKey:@"isReturnDataForIncompleteSession"] boolValue];
51
+ }
52
+ if (facialRecognitionSpecification) {
53
+ // Enable help page for face recognition
54
+ enrollmentBuilder.enableFacialRecognition = TRUE;
55
+
56
+ // Enable enroll face option
57
+ if (facialRecognitionSpecification[@"enrollFace"]) {
58
+ enrollmentBuilder.enrollFace = [[facialRecognitionSpecification valueForKey:@"enrollFace"] boolValue];
59
+ }
60
+
61
+ if (facialRecognitionSpecification[@"scanMinimumMatchLevel"]) {
62
+ enrollmentBuilder.scanMinimumMatchLevel = [[facialRecognitionSpecification valueForKey:@"scanMinimumMatchLevel"] integerValue];
63
+ }
64
+
65
+ if (facialRecognitionSpecification[@"readMinimumMatchLevel"]) {
66
+ enrollmentBuilder.readMinimumMatchLevel = [[facialRecognitionSpecification valueForKey:@"readMinimumMatchLevel"] integerValue];
67
+ }
68
+ if (facialRecognitionSpecification[@"maxAttempts"]) {
69
+ int maxAttempts = [[facialRecognitionSpecification valueForKey:@"maxAttempts"] intValue];
70
+ if (maxAttempts > 0) {
71
+ enrollmentBuilder.facialRecognitionMaxAttempts = maxAttempts;
72
+ }
73
+ }
74
+ }
75
+
76
+ if(lookupConfiguration){
77
+ NSMutableArray *lookupDocumentTypes = [[NSMutableArray alloc] init];
78
+ if(lookupConfiguration[@"documentList"]){
79
+ for (NSString *document in lookupConfiguration[@"documentList"]) {
80
+ UQDocumentConfig *documentConfig = [[UQDocumentConfig alloc] initWithDocumentTypeName:document];
81
+ [lookupDocumentTypes addObject:[NSNumber numberWithInteger:[documentConfig documentType]]];
82
+ }
83
+ }
84
+ if (lookupDocumentTypes.count) {
85
+ [enrollmentBuilder enableLookup:lookupDocumentTypes];
86
+ }
87
+ else {
88
+ [enrollmentBuilder enableLookup];
89
+ }
90
+ }
91
+ if (backgroundCheckConfiguration) {
92
+ BOOL isDisableConsent = FALSE;
93
+ BackgroundCheckType type = RDC;
94
+ if (backgroundCheckConfiguration[@"disableConsent"]) {
95
+ isDisableConsent = [[backgroundCheckConfiguration valueForKey:@"disableConsent"] boolValue];
96
+ }
97
+ if (backgroundCheckConfiguration[@"backgroudCheckType"]) {
98
+ if ([backgroundCheckConfiguration[@"backgroudCheckType"] isEqual:@"RDC"]) {
99
+ type = RDC;
100
+ } else {
101
+ type = DOW_JONES;
102
+ }
103
+ }
104
+ BOOL isMonitoringEnabled = FALSE;
105
+ if (backgroundCheckConfiguration[@"monitoringEnabled"]) {
106
+ isMonitoringEnabled = [[backgroundCheckConfiguration valueForKey:@"monitoringEnabled"] boolValue];
107
+ }
108
+ BOOL isSkipView = FALSE;
109
+ if (backgroundCheckConfiguration[@"skipView"]) {
110
+ isSkipView = [[backgroundCheckConfiguration valueForKey:@"skipView"] boolValue];
111
+ }
112
+ [enrollmentBuilder enableBackgroundCheck:isDisableConsent type:type monitoring:isMonitoringEnabled skipView:isSkipView];
113
+ }
114
+ for (NSDictionary *document in documentList) {
115
+ NSString* documentType = document[@"documentType"];
116
+ UQDocumentConfig *documentObject = [[UQDocumentConfig alloc] initWithDocumentTypeName:documentType];
117
+ if(documentObject.documentType == UNSPECIFY){
118
+ continue;
119
+ }
120
+
121
+ UQScanConfig *scanConfig = [[UQScanConfig alloc] init];
122
+ if (document[@"isHelpPageDisabled"]) {
123
+ scanConfig.disableHelpPage = [[document valueForKey:@"isHelpPageDisabled"] boolValue];
124
+ }
125
+ if (document[@"faceScanMinimumMatchLevel"]) {
126
+ scanConfig.faceMinimumMatchLevel = [[document valueForKey:@"faceScanMinimumMatchLevel"] intValue];
127
+ }
128
+ if (document[@"minimumAge"]) {
129
+ int minimumAge = [[document valueForKey:@"minimumAge"] intValue];
130
+ if (minimumAge > 0) {
131
+ documentObject.enableAgeVerification = minimumAge;
132
+ }
133
+ }
134
+
135
+ BOOL isEnableFrontSideReview = false;
136
+ BOOL isEnableBackSideReview = false;
137
+
138
+ if (document[@"isFrontSideReviewEnabled"]) {
139
+ isEnableFrontSideReview = [[document valueForKey:@"isFrontSideReviewEnabled"] boolValue];
140
+ }
141
+ if (document[@"isBackSideReviewEnabled"]) {
142
+ isEnableBackSideReview = [[document valueForKey:@"isBackSideReviewEnabled"] boolValue];
143
+ }
144
+ [scanConfig enableScanReview:isEnableFrontSideReview backSide:isEnableBackSideReview];
145
+ if (document[@"isUploadEnabled"]) {
146
+ scanConfig.enableUpload = [[document valueForKey:@"isUploadEnabled"] boolValue];
147
+ }
148
+ documentObject.scan = scanConfig;
149
+
150
+ if (document[@"isExpiredDocumentValidateDisabled"]) {
151
+ documentObject.disableExpiryValidation = [[document valueForKey:@"isExpiredDocumentValidateDisabled"] boolValue];
152
+ }
153
+
154
+ if (document[@"isUserDataReviewDisabled"]) {
155
+ documentObject.disableUserDataReview = [[document valueForKey:@"isUserDataReviewDisabled"] boolValue];
156
+ }
157
+
158
+ if (document[@"readingConfiguration"]) {
159
+ if (@available(iOS 13, *)) {
160
+ NSDictionary *readingConfiguration = document[@"readingConfiguration"];
161
+
162
+ UQReadingConfig *readConfig = [[UQReadingConfig alloc] init];
163
+ readConfig.enableReading = TRUE;
164
+ if (readingConfiguration[@"forceReading"]) {
165
+ [readConfig forceReading:[[readingConfiguration valueForKey:@"forceReading"] boolValue]];
166
+ }
167
+ if (readingConfiguration[@"forceReadingIfSupported"]) {
168
+ [readConfig forceReadingIfSupported:[[readingConfiguration valueForKey:@"forceReadingIfSupported"] boolValue]];
169
+ }
170
+ if (document[@"faceReadMinimumMatchLevel"]) {
171
+ readConfig.faceMinimumMatchLevel = [[document valueForKey:@"faceReadMinimumMatchLevel"] intValue];
172
+ }
173
+ if (readingConfiguration[@"timeoutInSeconds"]) {
174
+ int timeoutInSeconds = [[readingConfiguration valueForKey:@"timeoutInSeconds"] intValue];
175
+ if (timeoutInSeconds > 0) {
176
+ readConfig.forceReadingTimeout = timeoutInSeconds;
177
+ }
178
+ }
179
+
180
+ documentObject.reading = readConfig;
181
+ }
182
+ }
183
+
184
+ [enrollmentBuilder add:documentObject];
185
+ }
186
+ // Add enrollment to builder
187
+ UQBuilderController *builderController = [UQBuilderController defaultBuilder];
188
+ builderController.delegate = self;
189
+ [builderController setEnrollment:enrollmentBuilder];
190
+ NSInteger appearanceMode = SYSTEM;
191
+ if (json[@"appearanceMode"]) {
192
+ if ([json[@"appearanceMode"] isEqualToString:@"LIGHT"]) {
193
+ appearanceMode = LIGHT;
194
+ } else if ([json[@"appearanceMode"] isEqualToString:@"DARK"]) {
195
+ appearanceMode = DARK;
196
+ }
197
+ }
198
+ [builderController setAppearanceMode:appearanceMode];
199
+ // Start enrollment flow
200
+ // accessToken reuire, if no token the UQExceptionInvalidToken will throw
201
+
202
+ dispatch_async(dispatch_get_main_queue(), ^(void) {
203
+ UIWindow *window = [UIApplication sharedApplication].keyWindow;
204
+ UIViewController *rootViewController = window.rootViewController;
205
+ builderController.appViewController = rootViewController;
206
+ [builderController performEnrollmentWithToken:authorizationToken optionNonce:nonce];
207
+ });
208
+ } else {
209
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
210
+ status.statusCode = UNEXPECTED_ERROR;
211
+ status.message = @"Expected enrollment object as argument.";
212
+ status.statusTask = -1;
213
+ [self sendPluginError:status];
214
+ }
215
+ }
216
+ @catch (NSException *exception) {
217
+ NSLog(@"%@", exception.callStackSymbols);
218
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
219
+ status.statusCode = UNEXPECTED_ERROR;
220
+ status.message = exception.reason;
221
+ status.statusTask = -1;
222
+ [self sendPluginError:status];
223
+ }
224
+ }
225
+
226
+ - (void) didEnrollmentFailWithError:(NSError *)error {
227
+ NSLog(@"Error %ld %@", (long)error.code, error.localizedDescription);
228
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
229
+ status.statusCode = UNEXPECTED_ERROR;
230
+ status.message = error.localizedDescription;
231
+ status.statusTask = -1;
232
+ [self sendPluginError:status];
233
+ }
234
+
235
+ - (void) didEnrollmentCompleteWithInfo:(NSString *)jwsString {
236
+ NSMutableDictionary *jsonResults = [[NSMutableDictionary alloc]init];
237
+ [jsonResults setValue:jwsString forKey:@"result"];
238
+ self.promiseResolve(jsonResults);
239
+ }
240
+
241
+ - (void) didEnrollmentIncompleteWithStatus:(UQSessionStatus *)status {
242
+ [self sendPluginError:status];
243
+ }
244
+
245
+ RCT_EXPORT_METHOD(recover:(NSString *)recoverObj resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
246
+ self.promiseResolve = resolve;
247
+ self.promiseReject = reject;
248
+ @try {
249
+ if (recoverObj != nil && [recoverObj length] > 0) {
250
+ NSData *data = [recoverObj dataUsingEncoding:NSUTF8StringEncoding];
251
+ id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
252
+
253
+ UQAccountRecoveryBuilder *accountRecoveryBuilder = [[UQAccountRecoveryBuilder alloc] init];
254
+ accountRecoveryBuilder.authorizationToken = json[@"token"];
255
+ accountRecoveryBuilder.enrollmentIdentifier = json[@"enrollmentIdentifier"];
256
+ accountRecoveryBuilder.nonce = json[@"nonce"];
257
+ if (json[@"isRootedDeviceAllowed"]) {
258
+ accountRecoveryBuilder.isRootedDeviceAllowed = [[json valueForKey:@"isRootedDeviceAllowed"] boolValue];
259
+ }
260
+ if (json[@"minimumMatchLevel"]) {
261
+ accountRecoveryBuilder.minimumMatchLevel = [[json valueForKey:@"minimumMatchLevel"] intValue];
262
+ }
263
+
264
+ if (json[@"maxAttempts"]) {
265
+ int maxAttempts = [[json valueForKey:@"maxAttempts"] intValue];
266
+ if (maxAttempts > 0) {
267
+ accountRecoveryBuilder.maxAttempts = maxAttempts;
268
+ }
269
+ }
270
+
271
+ if (json[@"isReturnDataForIncompleteSession"]) {
272
+ accountRecoveryBuilder.returnDataForIncompleteSession = [[json valueForKey:@"isReturnDataForIncompleteSession"] boolValue];
273
+ }
274
+
275
+ UQBuilderController *builderController = [UQBuilderController defaultBuilder];
276
+ builderController.delegate = self;
277
+ UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
278
+ builderController.appViewController = rootViewController;
279
+ [builderController setAccountRecovery:accountRecoveryBuilder];
280
+
281
+ NSInteger appearanceMode = SYSTEM;
282
+ if (json[@"appearanceMode"]) {
283
+ if ([json[@"appearanceMode"] isEqualToString:@"LIGHT"]) {
284
+ appearanceMode = LIGHT;
285
+ } else if ([json[@"appearanceMode"] isEqualToString:@"DARK"]) {
286
+ appearanceMode = DARK;
287
+ }
288
+ }
289
+ [builderController setAppearanceMode:appearanceMode];
290
+
291
+
292
+
293
+ [builderController performAccountRecovery];
294
+ } else {
295
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
296
+ status.statusCode = UNEXPECTED_ERROR;
297
+ status.message = @"Expected account recovery object as argument.";
298
+ status.statusTask = -1;
299
+ [self sendPluginError:status];
300
+ }
301
+ }
302
+ @catch (NSException *exception) {
303
+ NSLog(@"%@", exception.callStackSymbols);
304
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
305
+ status.statusCode = UNEXPECTED_ERROR;
306
+ status.message = exception.reason;
307
+ status.statusTask = -1;
308
+ [self sendPluginError:status];
309
+ }
310
+ }
311
+
312
+ - (void)didAccountRecoveryCompleteWithInfo:(nonnull NSString *)jwsString {
313
+ NSMutableDictionary *jsonResults = [[NSMutableDictionary alloc]init];
314
+ [jsonResults setValue:jwsString forKey:@"result"];
315
+ self.promiseResolve(jsonResults);
316
+ }
317
+
318
+ - (void)didAccountRecoveryFailWithError:(nonnull NSError *)error {
319
+ NSLog(@"Error %ld %@", (long)error.code, error.localizedDescription);
320
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
321
+ status.statusCode = UNEXPECTED_ERROR;
322
+ status.message = error.localizedDescription;
323
+ status.statusTask = -1;
324
+ [self sendPluginError:status];
325
+ }
326
+
327
+ - (void)didAccountRecoveryIncompleteWithStatus:(UQSessionStatus *)status {
328
+ [self sendPluginError:status];
329
+ }
330
+
331
+ RCT_EXPORT_METHOD(faceSession:(NSString *)configuration resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
332
+ self.promiseResolve = resolve;
333
+ self.promiseReject = reject;
334
+ @try {
335
+ if (configuration != nil && [configuration length] > 0) {
336
+ NSData *data = [configuration dataUsingEncoding:NSUTF8StringEncoding];
337
+ id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
338
+
339
+ UQFaceSessionBuilder *faceSessionBuilder = [[UQFaceSessionBuilder alloc] init];
340
+ faceSessionBuilder.authorizationToken = json[@"token"];
341
+ faceSessionBuilder.sessionId = json[@"sessionId"];
342
+ faceSessionBuilder.nonce = json[@"nonce"];
343
+ if (json[@"isRootedDeviceAllowed"]) {
344
+ faceSessionBuilder.isRootedDeviceAllowed = [[json valueForKey:@"isRootedDeviceAllowed"] boolValue];
345
+ }
346
+ if (json[@"minimumMatchLevel"]) {
347
+ faceSessionBuilder.minimumMatchLevel = [[json valueForKey:@"minimumMatchLevel"] intValue];
348
+ }
349
+
350
+ if (json[@"maxAttempts"]) {
351
+ int maxAttempts = [[json valueForKey:@"maxAttempts"] intValue];
352
+ if (maxAttempts > 0) {
353
+ faceSessionBuilder.maxAttempts = maxAttempts;
354
+ }
355
+ }
356
+
357
+ if (json[@"isReturnDataForIncompleteSession"]) {
358
+ faceSessionBuilder.returnDataForIncompleteSession = [[json valueForKey:@"isReturnDataForIncompleteSession"] boolValue];
359
+ }
360
+
361
+ UQBuilderController *builderController = [UQBuilderController defaultBuilder];
362
+ builderController.delegate = self;
363
+ UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
364
+ builderController.appViewController = rootViewController;
365
+ [builderController setFaceSession:faceSessionBuilder];
366
+
367
+ NSInteger appearanceMode = SYSTEM;
368
+ if (json[@"appearanceMode"]) {
369
+ if ([json[@"appearanceMode"] isEqualToString:@"LIGHT"]) {
370
+ appearanceMode = LIGHT;
371
+ } else if ([json[@"appearanceMode"] isEqualToString:@"DARK"]) {
372
+ appearanceMode = DARK;
373
+ }
374
+ }
375
+ [builderController setAppearanceMode:appearanceMode];
376
+
377
+ [builderController performFaceSession];
378
+ } else {
379
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
380
+ status.statusCode = UNEXPECTED_ERROR;
381
+ status.message = @"Expected face session configuration as argument.";
382
+ status.statusTask = -1;
383
+ [self sendPluginError:status];
384
+ }
385
+ }
386
+ @catch (NSException *exception) {
387
+ NSLog(@"%@", exception.callStackSymbols);
388
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
389
+ status.statusCode = UNEXPECTED_ERROR;
390
+ status.message = exception.reason;
391
+ status.statusTask = -1;
392
+ [self sendPluginError:status];
393
+ }
394
+ }
395
+
396
+ - (void)didFaceSessionCompleteWithInfo:(nonnull NSString *)jwsString {
397
+ NSMutableDictionary *jsonResults = [[NSMutableDictionary alloc]init];
398
+ [jsonResults setValue:jwsString forKey:@"result"];
399
+ self.promiseResolve(jsonResults);
400
+ }
401
+
402
+ - (void)didFaceSessionFailWithError:(nonnull NSError *)error {
403
+ NSLog(@"Error %ld %@", (long)error.code, error.localizedDescription);
404
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
405
+ status.statusCode = UNEXPECTED_ERROR;
406
+ status.message = error.localizedDescription;
407
+ status.statusTask = -1;
408
+ [self sendPluginError:status];
409
+ }
410
+
411
+ - (void)didFaceSessionIncompleteWithStatus:(UQSessionStatus *)status {
412
+ [self sendPluginError:status];
413
+ }
414
+
415
+ - (void) didRootedDeviceDetected:(NSString *)info {
416
+ UQSessionStatus *status =[[UQSessionStatus alloc] init];
417
+ status.statusCode = UNEXPECTED_ERROR;
418
+ status.message = info;
419
+ status.statusTask = -1;
420
+ [self sendPluginError:status];
421
+ }
422
+
423
+ - (void)sendPluginError:(UQSessionStatus *)status {
424
+ NSString *code = nil;
425
+ switch (status.statusCode) {
426
+ case USER_CANCEL:
427
+ code = @"USER_CANCEL";
428
+ break;
429
+ case SESSION_EXPIRED:
430
+ code = @"SESSION_EXPIRED";
431
+ break;
432
+ case UNEXPECTED_ERROR:
433
+ code = @"UNEXPECTED_ERROR";
434
+ break;
435
+ case SESSION_INVALIDATED_CHIP_VALIDATION_FAILED:
436
+ code = @"SESSION_INVALIDATED_CHIP_VALIDATION_FAILED";
437
+ break;
438
+ case SESSION_INVALIDATED_READING_NOT_SUPPORTED:
439
+ code = @"SESSION_INVALIDATED_READING_NOT_SUPPORTED";
440
+ break;
441
+ case SESSION_INVALIDATED_READING_INVALID_DOCUMENT:
442
+ code = @"SESSION_INVALIDATED_READING_INVALID_DOCUMENT";
443
+ break;
444
+ case SESSION_INVALIDATED_FACE_RECOGNITION_TOO_MANY_ATTEMPTS:
445
+ code = @"SESSION_INVALIDATED_FACE_RECOGNITION_TOO_MANY_ATTEMPTS";
446
+ break;
447
+ }
448
+ NSString *task = nil;
449
+ switch (status.statusTask) {
450
+ case SCAN:
451
+ task = @"SCAN";
452
+ break;
453
+ case READING:
454
+ task = @"READING";
455
+ break;
456
+ case FACE:
457
+ task = @"FACE";
458
+ break;
459
+ case BACKGROUND_CHECK:
460
+ task = @"BACKGROUND_CHECK";
461
+ break;
462
+ }
463
+ NSMutableDictionary *error = [[NSMutableDictionary alloc]init];
464
+ [error setValue:code forKey:@"code"];
465
+ [error setValue:status.message forKey:@"message"];
466
+ [error setValue:task forKey:@"task"];
467
+ [error setValue:status.data forKey:@"data"];
468
+
469
+ NSError *err = nil;
470
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:error options:NSJSONWritingPrettyPrinted error:&err];
471
+
472
+ NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
473
+ self.promiseReject(jsonString, nil, nil);
474
+ }
475
+
476
+ -(void)startObserving {
477
+ if(tracer != nil) {
478
+ tracer.hasListeners = YES;
479
+ }
480
+ }
481
+
482
+ -(void)stopObserving {
483
+ if(tracer != nil) {
484
+ tracer.hasListeners = NO;
485
+ }
486
+ }
487
+
488
+ - (NSArray<NSString *> *)supportedEvents {
489
+ return @[@"TraceEvent"];
490
+ }
491
+
492
+ @end
493
+
494
+
495
+ @implementation MyTracer
496
+
497
+ - (void)trace:(UQTrace *)trace {
498
+ NSMutableDictionary* parameters = [[NSMutableDictionary alloc] init];
499
+
500
+ if(nil != trace.sessionId){
501
+ [parameters setValue:trace.sessionId forKey:@"sessionId"];
502
+ }
503
+ [parameters setValue:trace.event->name forKey:@"event"];
504
+ [parameters setValue:trace.status->name forKey:@"status"];
505
+
506
+ NSString *timeStamp = [self timeStamp:trace.timestamp];
507
+ [parameters setValue:timeStamp forKey:@"timestamp"];
508
+
509
+ if (TP_NULL != trace.page) {
510
+ [parameters setValue:trace.page->name forKey:@"page"];
511
+ }
512
+ if (TSC_NULL != trace.statusCode) {
513
+ [parameters setValue:trace.statusCode->name forKey:@"statusCode"];
514
+ }
515
+ if (trace.documentType != UNSPECIFY) {
516
+ UQDocumentConfig *document = [[UQDocumentConfig alloc] initWithDocumentType:trace.documentType];
517
+ [parameters setValue:document.documentName forKey:@"documentType"];
518
+ }
519
+ if (trace.statusMessage) {
520
+ [parameters setValue:trace.statusMessage forKey:@"statusMessage"];
521
+ }
522
+
523
+ NSError *err = nil;
524
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:&err];
525
+
526
+ NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
527
+ if(_hasListeners) {
528
+ [_emitter sendEventWithName:@"TraceEvent" body:jsonString];
529
+ }
530
+ }
531
+
532
+ - (NSString *)timeStamp:(NSDate *)currentDate {
533
+ return [NSDateFormatter localizedStringFromDate:currentDate
534
+ dateStyle:NSDateFormatterFullStyle
535
+ timeStyle:NSDateFormatterFullStyle];
536
+ }
537
+
538
+ @end