diff --git a/Sources/BranchSDK/BNCODMInfoCollector.m b/Sources/BranchSDK/BNCODMInfoCollector.m index d17f2ad19..4c4a81262 100644 --- a/Sources/BranchSDK/BNCODMInfoCollector.m +++ b/Sources/BranchSDK/BNCODMInfoCollector.m @@ -138,6 +138,7 @@ typedef NS_ENUM(NSInteger, ODCInteractionType) { }; [invocation setArgument:&_odmFetchCompletion atIndex:3]; + [invocation retainArguments]; [invocation invoke]; [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"fetchInfo:completion: invoked successfully."] error:nil]; diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 285c9245e..ef2fd27c7 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -279,6 +279,7 @@ - (id)initWithInterface:(BNCServerInterface *)interface } static Class bnc_networkServiceClass = NULL; +static callbackForTracingRequests bnc_tracingCallback = nil; + (void)setNetworkServiceClass:(Class)networkServiceClass { @synchronized ([Branch class]) { @@ -706,6 +707,10 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options automaticallyDispla [self initSessionWithLaunchOptions:options isReferrable:isReferrable explicitlyRequestedReferrable:YES automaticallyDisplayController:automaticallyDisplayController registerDeepLinkHandler:callback]; } ++ (void) setCallbackForTracingRequests: (callbackForTracingRequests) callback { + bnc_tracingCallback = callback; +} + #pragma mark - Actual Init Session - (void)initSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)isReferrable explicitlyRequestedReferrable:(BOOL)explicitlyRequestedReferrable automaticallyDisplayController:(BOOL)automaticallyDisplayController registerDeepLinkHandlerUsingBranchUniversalObject:(callbackWithBranchUniversalObject)callback { @@ -2170,6 +2175,7 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS } req.callback = initSessionCallback; req.urlString = urlString; + req.traceCallback = bnc_tracingCallback; [self.requestQueue insert:req at:0]; diff --git a/Sources/BranchSDK/BranchInstallRequest.m b/Sources/BranchSDK/BranchInstallRequest.m index 1c3c0a510..6d3bac230 100644 --- a/Sources/BranchSDK/BranchInstallRequest.m +++ b/Sources/BranchSDK/BranchInstallRequest.m @@ -22,7 +22,10 @@ - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key ca BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:key UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *params = [factory dataForInstallWithURLString:self.urlString]; - [serverInterface postRequest:params url:[[BNCServerAPI sharedInstance] installServiceURL] key:key callback:callback]; + self.requestParams = [params copy]; + self.requestServiceURL = [[BNCServerAPI sharedInstance] installServiceURL]; + + [serverInterface postRequest:params url:self.requestServiceURL key:key callback:callback]; } - (NSString *)getActionName { diff --git a/Sources/BranchSDK/BranchOpenRequest.m b/Sources/BranchSDK/BranchOpenRequest.m index 7b5a440bb..4d9ea41c2 100644 --- a/Sources/BranchSDK/BranchOpenRequest.m +++ b/Sources/BranchSDK/BranchOpenRequest.m @@ -50,14 +50,20 @@ - (id)initWithCallback:(callbackWithStatus)callback isInstall:(BOOL)isInstall { - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback { BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:key UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; NSDictionary *params = [factory dataForOpenWithURLString:self.urlString]; - + self.requestParams = [params copy]; + self.requestServiceURL = [[BNCServerAPI sharedInstance] openServiceURL]; [serverInterface postRequest:params - url:[[BNCServerAPI sharedInstance] openServiceURL] + url: self.requestServiceURL key:key callback:callback]; } - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { + + if (self.traceCallback) { + self.traceCallback(self.urlString, self.requestParams, response.data, error, self.requestServiceURL); + } + BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; if (error && preferenceHelper.dropURLOpen) { // Ignore this response from the server. Dummy up a response: diff --git a/Sources/BranchSDK/Private/BranchOpenRequest.h b/Sources/BranchSDK/Private/BranchOpenRequest.h index ec5717cd6..30b0ea1c3 100644 --- a/Sources/BranchSDK/Private/BranchOpenRequest.h +++ b/Sources/BranchSDK/Private/BranchOpenRequest.h @@ -15,6 +15,9 @@ @property (nonatomic, copy, readwrite) NSString *urlString; @property (assign, nonatomic) BOOL isFromArchivedQueue; @property (nonatomic, copy) callbackWithStatus callback; +@property (nonatomic, copy) callbackForTracingRequests traceCallback; +@property (strong, nonatomic) NSDictionary *requestParams; +@property (nonatomic, copy, readwrite) NSString *requestServiceURL; + (void) waitForOpenResponseLock; + (void) releaseOpenResponseLock; diff --git a/Sources/BranchSDK/Public/BNCCallbacks.h b/Sources/BranchSDK/Public/BNCCallbacks.h index 88669acf6..4c2ff7484 100644 --- a/Sources/BranchSDK/Public/BNCCallbacks.h +++ b/Sources/BranchSDK/Public/BNCCallbacks.h @@ -21,3 +21,4 @@ typedef void (^callbackWithList) (NSArray * _Nullable list, NSError * _Nullable typedef void (^callbackWithUrlAndSpotlightIdentifier) (NSString * _Nullable url, NSString * _Nullable spotlightIdentifier, NSError * _Nullable error); typedef void (^callbackWithBranchUniversalObject) (BranchUniversalObject * _Nullable universalObject, BranchLinkProperties * _Nullable linkProperties, NSError * _Nullable error); typedef void (^callbackWithData) (NSData * _Nullable data, NSError * _Nullable error); +typedef void (^callbackForTracingRequests) ( NSString * _Nullable url, NSDictionary * _Nullable request, NSDictionary * _Nullable response, NSError * _Nullable error, NSString * requestServiceURL); diff --git a/Sources/BranchSDK/Public/Branch.h b/Sources/BranchSDK/Public/Branch.h index 0983a5168..f552cdd9a 100644 --- a/Sources/BranchSDK/Public/Branch.h +++ b/Sources/BranchSDK/Public/Branch.h @@ -602,6 +602,8 @@ Sets a custom base safetrack URL for non-linking calls to the Branch API. + (void)setSafetrackAPIURL:(NSString *)url ; ++ (void)setCallbackForTracingRequests: (callbackForTracingRequests) callback ; + /** @brief Use the `validateSDKIntegration` method as a debugging aid to assure that you've integrated the Branch SDK correctly.