Skip to content

fix(ios): update native network logging method signature #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions example/ios/InstabugTests/InstabugApiTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#import "InstabugApi.h"
#import "Instabug/Instabug.h"
#import "Util/Instabug+Test.h"
#import "Util/IBGNetworkLogger+Test.h"
#import "IBGNetworkLogger+CP.h"
#import "Flutter/Flutter.h"

@interface InstabugTests : XCTestCase
Expand Down Expand Up @@ -435,7 +435,11 @@ - (void)testNetworkLog {
duration:duration.integerValue
gqlQueryName:nil
serverErrorMessage:nil
]);
isW3cCaughted:nil
partialID:nil
timestamp:nil
generatedW3CTraceparent:nil
caughtedW3CTraceparent:nil]);
}

- (void)testWillRedirectToAppStore {
Expand Down
2 changes: 0 additions & 2 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
CC359DB82937720C0067A924 /* ApmApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ApmApiTests.m; sourceTree = "<group>"; };
CC3D69E6293F47FC000DCE54 /* ArgsRegistryTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ArgsRegistryTests.m; sourceTree = "<group>"; };
CC78720E293CA8EE008CB2A5 /* Instabug+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Instabug+Test.h"; sourceTree = "<group>"; };
CC787211293CAB28008CB2A5 /* IBGNetworkLogger+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "IBGNetworkLogger+Test.h"; sourceTree = "<group>"; };
CC9925D1293DEB0B001FD3EE /* CrashReportingApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CrashReportingApiTests.m; sourceTree = "<group>"; };
CC9925D4293DF534001FD3EE /* FeatureRequestsApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FeatureRequestsApiTests.m; sourceTree = "<group>"; };
CC9925D6293DFB03001FD3EE /* InstabugLogApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InstabugLogApiTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -216,7 +215,6 @@
children = (
BE26C80C2BD55575009FECCF /* IBGCrashReporting+CP.h */,
CC78720E293CA8EE008CB2A5 /* Instabug+Test.h */,
CC787211293CAB28008CB2A5 /* IBGNetworkLogger+Test.h */,
CC198C62293E2392007077C8 /* IBGSurvey+Test.h */,
);
path = Util;
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'dart:async';
import 'dart:developer';
import 'dart:io';
import 'dart:convert';
import 'package:http/http.dart' as http;

import 'package:flutter/material.dart';
import 'package:instabug_flutter/instabug_flutter.dart';
import 'package:instabug_http_client/instabug_http_client.dart';
import 'package:instabug_flutter_example/src/app_routes.dart';
import 'package:instabug_flutter_example/src/widget/nested_view.dart';

Expand Down
2 changes: 2 additions & 0 deletions example/lib/src/components/network_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class NetworkContent extends StatefulWidget {
}

class _NetworkContentState extends State<NetworkContent> {
final http = InstabugHttpClient();

final endpointUrlController = TextEditingController();

@override
Expand Down
8 changes: 8 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ packages:
relative: true
source: path
version: "13.4.0"
instabug_http_client:
dependency: "direct main"
description:
name: instabug_http_client
sha256: "7d52803c0dd639f6dddbe07333418eb251ae02f3f9f4d30402517533ca692784"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
leak_tracker:
dependency: transitive
description:
Expand Down
5 changes: 5 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies:
http: ^0.13.0
instabug_flutter:
path: ../
instabug_http_client: ^2.4.0

dev_dependencies:
espresso: 0.2.0+5
Expand All @@ -35,6 +36,10 @@ dev_dependencies:
sdk: flutter
flutter_lints: 1.0.4

dependency_overrides:
instabug_flutter:
path: ../

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down
51 changes: 23 additions & 28 deletions ios/Classes/Modules/InstabugApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ - (void)networkLogData:(NSDictionary<NSString *, id> *)data error:(FlutterError
NSString *method = data[@"method"];
NSString *requestBody = data[@"requestBody"];
NSString *responseBody = data[@"responseBody"];
int32_t responseCode = [data[@"responseCode"] integerValue];
int32_t responseCode = (int32_t) [data[@"responseCode"] integerValue];
int64_t requestBodySize = [data[@"requestBodySize"] integerValue];
int64_t responseBodySize = [data[@"responseBodySize"] integerValue];
int32_t errorCode = [data[@"errorCode"] integerValue];
int32_t errorCode = (int32_t) [data[@"errorCode"] integerValue];
NSString *errorDomain = data[@"errorDomain"];
NSDictionary *requestHeaders = data[@"requestHeaders"];
if ([requestHeaders count] == 0) {
Expand All @@ -286,32 +286,27 @@ - (void)networkLogData:(NSDictionary<NSString *, id> *)data error:(FlutterError
serverErrorMessage = data[@"serverErrorMessage"];
}

SEL networkLogSEL = NSSelectorFromString(@"addNetworkLogWithUrl:method:requestBody:requestBodySize:responseBody:responseBodySize:responseCode:requestHeaders:responseHeaders:contentType:errorDomain:errorCode:startTime:duration:gqlQueryName:serverErrorMessage:");

if ([[IBGNetworkLogger class] respondsToSelector:networkLogSEL]) {
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[IBGNetworkLogger class] methodSignatureForSelector:networkLogSEL]];
[inv setSelector:networkLogSEL];
[inv setTarget:[IBGNetworkLogger class]];

[inv setArgument:&(url) atIndex:2];
[inv setArgument:&(method) atIndex:3];
[inv setArgument:&(requestBody) atIndex:4];
[inv setArgument:&(requestBodySize) atIndex:5];
[inv setArgument:&(responseBody) atIndex:6];
[inv setArgument:&(responseBodySize) atIndex:7];
[inv setArgument:&(responseCode) atIndex:8];
[inv setArgument:&(requestHeaders) atIndex:9];
[inv setArgument:&(responseHeaders) atIndex:10];
[inv setArgument:&(contentType) atIndex:11];
[inv setArgument:&(errorDomain) atIndex:12];
[inv setArgument:&(errorCode) atIndex:13];
[inv setArgument:&(startTime) atIndex:14];
[inv setArgument:&(duration) atIndex:15];
[inv setArgument:&(gqlQueryName) atIndex:16];
[inv setArgument:&(serverErrorMessage) atIndex:17];

[inv invoke];
}
[IBGNetworkLogger addNetworkLogWithUrl:url
method:method
requestBody:requestBody
requestBodySize:requestBodySize
responseBody:responseBody
responseBodySize:responseBodySize
responseCode:responseCode
requestHeaders:requestHeaders
responseHeaders:responseHeaders
contentType:contentType
errorDomain:errorDomain
errorCode:errorCode
startTime:startTime
duration:duration
gqlQueryName:gqlQueryName
serverErrorMessage:serverErrorMessage
isW3cCaughted:nil
partialID:nil
timestamp:nil
generatedW3CTraceparent:nil
caughtedW3CTraceparent:nil];
}

- (void)willRedirectToStoreWithError:(FlutterError * _Nullable __autoreleasing *)error {
Expand Down
22 changes: 22 additions & 0 deletions ios/Classes/Util/IBGNetworkLogger+CP.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ NS_ASSUME_NONNULL_BEGIN

+ (void)disableAutomaticCapturingOfNetworkLogs;

+ (void)addNetworkLogWithUrl:(NSString *_Nonnull)url
method:(NSString *_Nonnull)method
requestBody:(NSString *_Nonnull)request
requestBodySize:(int64_t)requestBodySize
responseBody:(NSString *_Nonnull)response
responseBodySize:(int64_t)responseBodySize
responseCode:(int32_t)code
requestHeaders:(NSDictionary *_Nonnull)requestHeaders
responseHeaders:(NSDictionary *_Nonnull)responseHeaders
contentType:(NSString *_Nonnull)contentType
errorDomain:(NSString *_Nullable)errorDomain
errorCode:(int32_t)errorCode
startTime:(int64_t)startTime
duration:(int64_t) duration
gqlQueryName:(NSString * _Nullable)gqlQueryName
serverErrorMessage:(NSString * _Nullable)serverErrorMessage
isW3cCaughted:(NSNumber * _Nullable)isW3cCaughted
partialID:(NSNumber * _Nullable)partialID
timestamp:(NSNumber * _Nullable)timestamp
generatedW3CTraceparent:(NSString * _Nullable)generatedW3CTraceparent
caughtedW3CTraceparent:(NSString * _Nullable)caughtedW3CTraceparent;

@end

NS_ASSUME_NONNULL_END