7
7
#import " InstabugNetworkLoggerBridge.h"
8
8
#import " Util/IBGNetworkLogger+CP.h"
9
9
10
+
10
11
@implementation InstabugNtworkLoggerBridge
12
+ // @property NSMutableDictionary<NSString *, IBGURLRequestAsyncObfuscationCompletedHandler> *dictionary;
13
+
14
+
11
15
12
16
- (dispatch_queue_t )methodQueue {
13
17
return dispatch_get_main_queue ();
@@ -20,14 +24,16 @@ + (BOOL)requiresMainQueueSetup
20
24
21
25
- (NSArray <NSString *> *)supportedEvents {
22
26
return @[
23
- @" IBGpreInvocationHandler"
27
+ @" IBGpreInvocationHandler" ,
28
+ @" IBGNetworkLoggerHandler"
24
29
];
25
30
}
26
31
RCT_EXPORT_MODULE (IBGNetworkLogger)
27
32
28
33
bool hasListeners = NO;
29
34
30
35
36
+
31
37
// Will be called when this module's first listener is added.
32
38
-(void )startObserving {
33
39
hasListeners = YES ;
@@ -44,74 +50,76 @@ -(void)stopObserving {
44
50
resolve (@(IBGNetworkLogger.isNativeNetworkInterceptionFeatureEnabled ));
45
51
}
46
52
47
-
48
- // RCT_EXPORT_METHOD(registerNetworkLogsListener){
49
- // [IBGNetworkLogger setRequestObfuscationHandlerV2:^(NSURLRequest * _Nonnull request, void (^ _Nonnull completionHandler)(NSURLRequest * _Nonnull)) {
50
- // NSString *tempId = [[[NSUUID alloc] init] UUIDString];
51
- // self.dictionary[tempId] = completionHandler;
52
- //
53
- // // Ensure the URL, HTTP body, and headers are in the correct format
54
- // NSString *urlString = request.URL.absoluteString ?: @"";
55
- // NSString *bodyString = [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding] ?: @"";
56
- // NSDictionary *headerDict = request.allHTTPHeaderFields ?: @{};
57
- //
58
- // // Create the dictionary to send
59
- // NSDictionary *dict = @{
60
- // @"tempId": tempId,
61
- // @"url": urlString,
62
- // @"requestBody": bodyString,
63
- // @"requestHeader": headerDict
64
- // };
65
- //
66
- // // Send the event
67
- // [self sendEventWithName:@"IBGNetworkLoggerHandler" body:dict];
68
- //
69
- // }];
70
- // }
71
- //
72
- // RCT_EXPORT_METHOD(updateNetworkLogSnapshot:(NSString * _Nonnull)jsonString) {
73
- // // Properly initialize the NSMutableURLRequest
74
- // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
53
+ // RCT_EXPORT_METHOD(registerNetworkLogsListener){
75
54
//
76
- // // Convert jsonString to NSData
77
- // NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
55
+ // [IBGNetworkLogger setRequestAsyncObfuscationHandler:^(NSURLRequest *requestToBeObfuscated, IBGURLRequestAsyncObfuscationCompletedHandler completion) {
78
56
//
79
- // // Parse the JSON into a dictionary
80
- // NSError *error = nil;
81
- // NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
57
+ // NSString *tempId = [[[NSUUID alloc] init] UUIDString];
58
+ // self.dictionary[tempId] = completion;
82
59
//
83
- // // Check for JSON parsing errors
84
- // if (error) {
85
- // NSLog(@"Failed to parse JSON: %@", error);
86
- // return;
87
- // }
60
+ // // Ensure the URL, HTTP body, and headers are in the correct format
61
+ // NSString *urlString = requestToBeObfuscated.URL.absoluteString ?: @"";
62
+ // NSString *bodyString = [[NSString alloc] initWithData:requestToBeObfuscated.HTTPBody encoding:NSUTF8StringEncoding] ?: @"";
63
+ // NSDictionary *headerDict = requestToBeObfuscated.allHTTPHeaderFields ?: @{};
88
64
//
89
- // // Set the URL, HTTP body, and headers
90
- // request.URL = [NSURL URLWithString:dict[@"url"]];
91
- // request.HTTPBody = [dict[@"requestBody"] dataUsingEncoding:NSUTF8StringEncoding];
65
+ // // Create the dictionary to send
66
+ // NSDictionary *dict = @{
67
+ // @"tempId": tempId,
68
+ // @"url": urlString,
69
+ // @"requestBody": bodyString,
70
+ // @"requestHeader": headerDict
71
+ // };
92
72
//
93
- // // Ensure requestHeader is a dictionary
94
- // if ([dict[@"requestHeader"] isKindOfClass:[NSDictionary class]]) {
95
- // request.allHTTPHeaderFields = dict[@"requestHeader"];
96
- // } else {
97
- // NSLog(@"Invalid requestHeader format");
98
- // // return;
99
- // }
73
+ // // Send the event
74
+ // [self sendEventWithName:@"IBGNetworkLoggerHandler" body:dict];
100
75
//
101
- // // Ensure self.completion is not nil before calling it
102
- // NSString *tempId = dict[@"tempId"];
103
- // if ([tempId isKindOfClass:[NSString class]] && self.dictionary[tempId] != nil) {
104
- // ((IBGURLRequestObfuscationHandler)self.dictionary[tempId])(request);
105
- // } else {
106
- // NSLog(@"Not Available Completion");
107
- // }
108
- // }
109
- //
110
- // RCT_EXPORT_METHOD(setNetworkLoggingRequestFilterPredicateIOS: (BOOL)value){
111
- //
112
- // NSPredicate *requestPredicate = [NSPredicate predicateWithValue:(value) ? YES : NO];
113
- //
114
- // [IBGNetworkLogger setNetworkLoggingRequestFilterPredicate:requestPredicate responseFilterPredicate:nil];
115
- // }
76
+ // }];
77
+ // }
78
+
79
+
80
+ // RCT_EXPORT_METHOD(updateNetworkLogSnapshot:(NSString * _Nonnull)jsonString) {
81
+ // // Properly initialize the NSMutableURLRequest
82
+ // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
83
+ //
84
+ // // Convert jsonString to NSData
85
+ // NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
86
+ //
87
+ // // Parse the JSON into a dictionary
88
+ // NSError *error = nil;
89
+ // NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
90
+ //
91
+ // // Check for JSON parsing errors
92
+ // if (error) {
93
+ // NSLog(@"Failed to parse JSON: %@", error);
94
+ // return;
95
+ // }
96
+ //
97
+ // // Set the URL, HTTP body, and headers
98
+ // request.URL = [NSURL URLWithString:dict[@"url"]];
99
+ // request.HTTPBody = [dict[@"requestBody"] dataUsingEncoding:NSUTF8StringEncoding];
100
+ //
101
+ // // Ensure requestHeader is a dictionary
102
+ // if ([dict[@"requestHeader"] isKindOfClass:[NSDictionary class]]) {
103
+ // request.allHTTPHeaderFields = dict[@"requestHeader"];
104
+ // } else {
105
+ // NSLog(@"Invalid requestHeader format");
106
+ // // return;
107
+ // }
108
+ //
109
+ // // Ensure self.completion is not nil before calling it
110
+ // NSString *tempId = dict[@"tempId"];
111
+ // if ([tempId isKindOfClass:[NSString class]] && self.dictionary[tempId] != nil) {
112
+ // ((IBGURLRequestObfuscationHandler)self.dictionary[tempId])(request);
113
+ // } else {
114
+ // NSLog(@"Not Available Completion");
115
+ // }
116
+ // }
117
+
118
+ RCT_EXPORT_METHOD (setNetworkLoggingRequestFilterPredicateIOS: (BOOL )value){
119
+
120
+ NSPredicate *requestPredicate = [NSPredicate predicateWithValue: (value) ? YES : NO ];
121
+
122
+ [IBGNetworkLogger setNetworkLoggingRequestFilterPredicate: requestPredicate responseFilterPredicate: nil ];
123
+ }
116
124
117
125
@end
0 commit comments