diff --git a/RNInstabug.podspec b/RNInstabug.podspec index 40c480f4cb..21ae5fc720 100644 --- a/RNInstabug.podspec +++ b/RNInstabug.podspec @@ -16,5 +16,5 @@ Pod::Spec.new do |s| s.source_files = "ios/**/*.{h,m,mm}" s.dependency 'React-Core' - use_instabug!(s) + s.dependency 'Instabug' end diff --git a/examples/default/ios/InstabugTests/InstabugSampleTests.m b/examples/default/ios/InstabugTests/InstabugSampleTests.m index 70ef410258..742c2d77c5 100644 --- a/examples/default/ios/InstabugTests/InstabugSampleTests.m +++ b/examples/default/ios/InstabugTests/InstabugSampleTests.m @@ -331,7 +331,6 @@ - (void)testNetworkLogIOS { double startTime = 1719847101199; double duration = 150; NSString *gqlQueryName = nil; - NSString *serverErrorMessage = nil; [self.instabugBridge networkLogIOS:url method:method @@ -347,8 +346,7 @@ - (void)testNetworkLogIOS { errorCode:errorCode startTime:startTime duration:duration - gqlQueryName:gqlQueryName - serverErrorMessage:serverErrorMessage]; + gqlQueryName:gqlQueryName]; OCMVerify([mIBGNetworkLogger addNetworkLogWithUrl:url method:method @@ -364,8 +362,7 @@ - (void)testNetworkLogIOS { errorCode:errorCode startTime:startTime * 1000 duration:duration * 1000 - gqlQueryName:gqlQueryName - serverErrorMessage:serverErrorMessage]); + gqlQueryName:gqlQueryName]); } - (void)testSetFileAttachment { diff --git a/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m b/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m index a2030df9ae..7ee1871ea9 100644 --- a/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m +++ b/examples/default/ios/InstabugTests/InstabugSessionReplayTests.m @@ -16,8 +16,8 @@ @implementation InstabugSessionReplayTests - (void)setUp { - self.mSessionReplay = OCMClassMock([IBGSessionReplay class]); - self.bridge = [[InstabugSessionReplayBridge alloc] init]; + self.mSessionReplay = OCMClassMock([IBGSessionReplay class]); + self.bridge = [[InstabugSessionReplayBridge alloc] init]; } - (void)testSetEnabled { @@ -67,7 +67,54 @@ - (void)testGetSessionReplayLink { [self.bridge getSessionReplayLink:resolve :reject]; OCMVerify([self.mSessionReplay sessionReplayLink]); [self waitForExpectations:@[expectation] timeout:5.0]; - } +- (void)testSetSyncCallback { + id mockMetadata = OCMClassMock([IBGSessionMetadata class]); + id mockNetworkLog = OCMClassMock([IBGSessionMetadataNetworkLogs class]); + id partialMock = OCMPartialMock(self.bridge); + + XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Completion block should be called with the expected value"]; + + BOOL expectedValue = YES; + __block BOOL actualValue = NO; + + OCMStub([mockNetworkLog url]).andReturn(@"http://example.com"); + OCMStub([mockNetworkLog statusCode]).andReturn(200); + + OCMStub([mockMetadata device]).andReturn(@"ipohne"); + OCMStub([mockMetadata os]).andReturn(@"ios"); + OCMStub([mockMetadata appVersion]).andReturn(@"13.4.1"); + OCMStub([mockMetadata sessionDuration]).andReturn(20); + OCMStub([mockMetadata hasLinkToAppReview]).andReturn(NO); + OCMStub([mockMetadata launchType]).andReturn(LaunchTypeCold); + OCMStub([mockMetadata launchDuration]).andReturn(20); + OCMStub([mockMetadata bugsCount]).andReturn(10); + OCMStub([mockMetadata fatalCrashCount]).andReturn(10); + OCMStub([mockMetadata oomCrashCount]).andReturn(10); + OCMStub([mockMetadata networkLogs]).andReturn(@[mockNetworkLog]); + + SessionEvaluationCompletion sessionEvaluationCompletion = ^(BOOL shouldSync) { + actualValue = shouldSync; + [completionExpectation fulfill]; + }; + + OCMStub([partialMock sendEventWithName:@"IBGSessionReplayOnSyncCallback" body:OCMArg.any]).andDo(^(NSInvocation *invocation) { + [self.bridge evaluateSync:expectedValue]; + }); + + OCMStub([self.mSessionReplay setSyncCallbackWithHandler:[OCMArg checkWithBlock: ^BOOL(void(^handler)(IBGSessionMetadata *metadataObject, SessionEvaluationCompletion completion)) { + handler(mockMetadata, sessionEvaluationCompletion); + return YES; + }]]); + + [self.bridge setSyncCallback]; + [self waitForExpectationsWithTimeout:1 handler:nil]; + + OCMVerify([partialMock sendEventWithName:@"IBGSessionReplayOnSyncCallback" body:OCMArg.any]); + OCMVerifyAll(self.mSessionReplay); + XCTAssertEqual(actualValue, expectedValue); + } + + @end diff --git a/examples/default/ios/Podfile b/examples/default/ios/Podfile index 3d0c8ceedb..131ea74989 100644 --- a/examples/default/ios/Podfile +++ b/examples/default/ios/Podfile @@ -32,8 +32,8 @@ target 'InstabugExample' do target 'InstabugTests' do inherit! :complete pod 'OCMock' - # Pods for testing - end + pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec' + end post_install do |installer| react_native_post_install( diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 1da6e558ee..b90c3a0da2 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -38,12 +38,12 @@ PODS: - hermes-engine (0.72.3): - hermes-engine/Pre-built (= 0.72.3) - hermes-engine/Pre-built (0.72.3) - - Instabug (13.3.0) + - Instabug (13.4.0) - instabug-reactnative-ndk (0.1.0): - RCT-Folly (= 2021.07.22.00) - React-Core - libevent (2.1.12) - - OCMock (3.9.3) + - OCMock (3.9.4) - RCT-Folly (2021.07.22.00): - boost - DoubleConversion @@ -476,7 +476,7 @@ PODS: - RCT-Folly (= 2021.07.22.00) - React-Core - RNInstabug (13.3.0): - - Instabug (= 13.3.0) + - Instabug - React-Core - RNReanimated (3.5.4): - DoubleConversion @@ -524,6 +524,7 @@ DEPENDENCIES: - FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) + - Instabug (from `https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec`) - instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`) - libevent (~> 2.1.12) - OCMock @@ -580,7 +581,6 @@ SPEC REPOS: - fmt - Google-Maps-iOS-Utils - GoogleMaps - - Instabug - libevent - OCMock - SocketRocket @@ -599,6 +599,8 @@ EXTERNAL SOURCES: hermes-engine: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2023-03-20-RNv0.72.0-49794cfc7c81fb8f69fd60c3bbf85a7480cc5a77 + Instabug: + :podspec: https://ios-releases.instabug.com/custom/feature-dynamic-sampling-callback-add-apm-delegate/13.4.0/Instabug.podspec instabug-reactnative-ndk: :path: "../node_modules/instabug-reactnative-ndk" RCT-Folly: @@ -704,10 +706,10 @@ SPEC CHECKSUMS: Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac hermes-engine: 10fbd3f62405c41ea07e71973ea61e1878d07322 - Instabug: 4f26295103a330ec0236918359eef7ccaa74e2fa + Instabug: 16e4c013f2ae57ddca4966ea90736e48bbcdd2d5 instabug-reactnative-ndk: 960119a69380cf4cbe47ccd007c453f757927d17 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - OCMock: 300b1b1b9155cb6378660b981c2557448830bdc6 + OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74 RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 RCTRequired: a2faf4bad4e438ca37b2040cb8f7799baa065c18 RCTTypeSafety: cb09f3e4747b6d18331a15eb05271de7441ca0b3 @@ -748,7 +750,7 @@ SPEC CHECKSUMS: ReactCommon: 3ccb8fb14e6b3277e38c73b0ff5e4a1b8db017a9 RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495 RNGestureHandler: 6e46dde1f87e5f018a54fe5d40cd0e0b942b49ee - RNInstabug: a4ac0bd09123f6be7d58be541dc220acbaff8dc3 + RNInstabug: 80b369d623a473c31ff3b8b8ea1d17daaca44132 RNReanimated: ab2e96c6d5591c3dfbb38a464f54c8d17fb34a87 RNScreens: b21dc57dfa2b710c30ec600786a3fc223b1b92e7 RNSVG: 80584470ff1ffc7994923ea135a3e5ad825546b9 @@ -756,6 +758,6 @@ SPEC CHECKSUMS: SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce -PODFILE CHECKSUM: 281036e04bd4b9e7c2cc03a503b3245d3f1dd0dd +PODFILE CHECKSUM: f16fc6271767fab2dc19a52068caa1ca15e29e62 COCOAPODS: 1.12.0 diff --git a/ios/RNInstabug/ArgsRegistry.h b/ios/RNInstabug/ArgsRegistry.h index 09c8ac91c5..c7720e38fb 100644 --- a/ios/RNInstabug/ArgsRegistry.h +++ b/ios/RNInstabug/ArgsRegistry.h @@ -22,6 +22,7 @@ typedef NSDictionary ArgsDictionary; + (ArgsDictionary *) reproStates; + (ArgsDictionary *) locales; + (ArgsDictionary *)nonFatalExceptionLevel; ++ (ArgsDictionary *) launchType; + (NSDictionary *) placeholders; diff --git a/ios/RNInstabug/ArgsRegistry.m b/ios/RNInstabug/ArgsRegistry.m index 7099f4976c..707fdc9932 100644 --- a/ios/RNInstabug/ArgsRegistry.m +++ b/ios/RNInstabug/ArgsRegistry.m @@ -20,6 +20,7 @@ + (NSMutableDictionary *) getAll { [all addEntriesFromDictionary:ArgsRegistry.locales]; [all addEntriesFromDictionary:ArgsRegistry.nonFatalExceptionLevel]; [all addEntriesFromDictionary:ArgsRegistry.placeholders]; + [all addEntriesFromDictionary:ArgsRegistry.launchType]; return all; } @@ -241,4 +242,12 @@ + (ArgsDictionary *)nonFatalExceptionLevel { }; } ++ (ArgsDictionary *) launchType { + return @{ + @"hot": @(LaunchTypeHot), + @"cold": @(LaunchTypeCold), + @"unknown":@(LaunchTypeUnknown) + }; +} + @end diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index a3cfc21c13..a9f92fde44 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -120,9 +120,7 @@ errorCode:(double)errorCode startTime:(double)startTime duration:(double)duration - gqlQueryName:(NSString * _Nullable)gqlQueryName - serverErrorMessage:(NSString * _Nullable)serverErrorMessage; - + gqlQueryName:(NSString * _Nullable)gqlQueryName; /* +------------------------------------------------------------------------+ | Experiments | diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index dd18513163..abe1a6e453 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -297,8 +297,7 @@ - (dispatch_queue_t)methodQueue { errorCode:(double)errorCode startTime:(double)startTime duration:(double)duration - gqlQueryName:(NSString * _Nullable)gqlQueryName - serverErrorMessage:(NSString * _Nullable)serverErrorMessage) { + gqlQueryName:(NSString * _Nullable)gqlQueryName) { [IBGNetworkLogger addNetworkLogWithUrl:url method:method requestBody:requestBody @@ -313,8 +312,7 @@ - (dispatch_queue_t)methodQueue { errorCode:errorCode startTime:startTime * 1000 duration:duration * 1000 - gqlQueryName:gqlQueryName - serverErrorMessage:serverErrorMessage]; + gqlQueryName:gqlQueryName]; } RCT_EXPORT_METHOD(addPrivateView: (nonnull NSNumber *)reactTag) { diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.h b/ios/RNInstabug/InstabugSessionReplayBridge.h index 1f247ab26e..259ea1c146 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.h +++ b/ios/RNInstabug/InstabugSessionReplayBridge.h @@ -2,6 +2,7 @@ #import #import #import +#import @interface InstabugSessionReplayBridge : RCTEventEmitter /* @@ -20,6 +21,12 @@ - (void)getSessionReplayLink:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject; +- (void)setSyncCallback; + +- (void)evaluateSync:(BOOL)result; + +@property (atomic, copy) SessionEvaluationCompletion sessionEvaluationCompletion; + @end diff --git a/ios/RNInstabug/InstabugSessionReplayBridge.m b/ios/RNInstabug/InstabugSessionReplayBridge.m index bbaf7ffd6d..2c865ecb5f 100644 --- a/ios/RNInstabug/InstabugSessionReplayBridge.m +++ b/ios/RNInstabug/InstabugSessionReplayBridge.m @@ -18,7 +18,9 @@ + (BOOL)requiresMainQueueSetup } - (NSArray *)supportedEvents { - return @[]; + return @[ + @"IBGSessionReplayOnSyncCallback", + ]; } RCT_EXPORT_MODULE(IBGSessionReplay) @@ -45,6 +47,55 @@ + (BOOL)requiresMainQueueSetup resolve(link); } +- (NSArray *)getNetworkLogsArray: + (NSArray*) networkLogs { + NSMutableArray *networkLogsArray = [NSMutableArray array]; + + for (IBGSessionMetadataNetworkLogs* log in networkLogs) { + NSDictionary *nLog = @{@"url": log.url, @"statusCode": @(log.statusCode), @"duration": @(log.duration)}; + [networkLogsArray addObject:nLog]; + } + return networkLogsArray; +} + +- (NSDictionary *)getMetadataObjectMap:(IBGSessionMetadata *)metadataObject { + return @{ + @"appVersion": metadataObject.appVersion, + @"OS": metadataObject.os, + @"device": metadataObject.device, + @"sessionDurationInSeconds": @(metadataObject.sessionDuration), + @"hasLinkToAppReview": @(metadataObject.hasLinkToAppReview), + @"launchType": @(metadataObject.launchType), + @"launchDuration": @(metadataObject.launchDuration), + @"bugsCount": @(metadataObject.bugsCount), + @"fatalCrashCount": @(metadataObject.fatalCrashCount), + @"oomCrashCount": @(metadataObject.oomCrashCount), + @"networkLogs":[self getNetworkLogsArray:metadataObject.networkLogs] + }; +} + +RCT_EXPORT_METHOD(setSyncCallback) { + [IBGSessionReplay setSyncCallbackWithHandler:^(IBGSessionMetadata * _Nonnull metadataObject, SessionEvaluationCompletion _Nonnull completion) { + + [self sendEventWithName:@"IBGSessionReplayOnSyncCallback" + body:[self getMetadataObjectMap:metadataObject]]; + + self.sessionEvaluationCompletion = completion; + }]; +} + +RCT_EXPORT_METHOD(evaluateSync:(BOOL)result) { + + if (self.sessionEvaluationCompletion) { + + self.sessionEvaluationCompletion(result); + + self.sessionEvaluationCompletion = nil; + + } +} + + @synthesize description; @synthesize hash; diff --git a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h index 5ae464785f..771417cfbd 100644 --- a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h +++ b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h @@ -19,8 +19,7 @@ NS_ASSUME_NONNULL_BEGIN errorCode:(int32_t)errorCode startTime:(int64_t)startTime duration:(int64_t) duration - gqlQueryName:(NSString * _Nullable)gqlQueryName - serverErrorMessage:(NSString * _Nullable)serverErrorMessage; + gqlQueryName:(NSString * _Nullable)gqlQueryName; @end diff --git a/src/native/NativeConstants.ts b/src/native/NativeConstants.ts index 271f179b8d..cec8840055 100644 --- a/src/native/NativeConstants.ts +++ b/src/native/NativeConstants.ts @@ -194,4 +194,5 @@ interface NativeLaunchType { hot: any; cold: any; warm: any; + unknown: any; } diff --git a/src/native/NativeInstabug.ts b/src/native/NativeInstabug.ts index 3b72f5951f..223aec83d0 100644 --- a/src/native/NativeInstabug.ts +++ b/src/native/NativeInstabug.ts @@ -66,7 +66,6 @@ export interface InstabugNativeModule extends NativeModule { startTime: number, duration: number, gqlQueryName: string | undefined, - serverErrorMessage: string | undefined, ): void; setNetworkLoggingEnabled(isEnabled: boolean): void; diff --git a/src/utils/Enums.ts b/src/utils/Enums.ts index 39577bac89..c80b46f54f 100644 --- a/src/utils/Enums.ts +++ b/src/utils/Enums.ts @@ -236,6 +236,7 @@ export enum StringKey { export enum LaunchType { hot = constants.hot, cold = constants.cold, + unknown = constants.unknown, /** * android only */ diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index d4238f14f0..80f632a0d5 100644 --- a/src/utils/InstabugUtils.ts +++ b/src/utils/InstabugUtils.ts @@ -191,7 +191,6 @@ export function reportNetworkLog(network: NetworkData) { network.startTime, network.duration, network.gqlQueryName, - network.serverErrorMessage, ); } } diff --git a/test/utils/InstabugUtils.spec.ts b/test/utils/InstabugUtils.spec.ts index becfccc0e9..3ac83be274 100644 --- a/test/utils/InstabugUtils.spec.ts +++ b/test/utils/InstabugUtils.spec.ts @@ -323,7 +323,6 @@ describe('reportNetworkLog', () => { network.startTime, network.duration, network.gqlQueryName, - network.serverErrorMessage, ); }); });