diff --git a/Sources/BranchSDK/BNCPreferenceHelper.m b/Sources/BranchSDK/BNCPreferenceHelper.m index ff4eacafa..9934fe5f0 100644 --- a/Sources/BranchSDK/BNCPreferenceHelper.m +++ b/Sources/BranchSDK/BNCPreferenceHelper.m @@ -388,9 +388,11 @@ - (NSString *)sessionParams { - (void)setSessionParams:(NSString *)sessionParams { @synchronized (self) { + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Setting session params %@", sessionParams] error:nil]; if (sessionParams == nil || ![_sessionParams isEqualToString:sessionParams]) { _sessionParams = sessionParams; [self writeObjectToDefaults:BRANCH_PREFS_KEY_SESSION_PARAMS value:sessionParams]; + [[BranchLogger shared] logVerbose:@"Params set" error:nil]; } } } @@ -824,6 +826,8 @@ - (void) setAdUserDataUsageConsent:(BOOL)hasConsent { - (void) clearTrackingInformation { @synchronized(self) { + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"clearTrackingInformation"] error:nil]; + /* // Don't clear these self.randomizedDeviceToken = nil; diff --git a/Sources/BranchSDK/BNCReferringURLUtility.m b/Sources/BranchSDK/BNCReferringURLUtility.m index 3d7b63aac..79ce1cd1f 100644 --- a/Sources/BranchSDK/BNCReferringURLUtility.m +++ b/Sources/BranchSDK/BNCReferringURLUtility.m @@ -46,6 +46,8 @@ - (void)dealloc { - (void)parseReferringURL:(NSURL *)url { + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Parsing URL %@", url] error:nil]; + NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; for (NSURLQueryItem *item in components.queryItems) { if ([self isSupportedQueryParameter:item.name]) { diff --git a/Sources/BranchSDK/BNCServerInterface.m b/Sources/BranchSDK/BNCServerInterface.m index 63559c3a8..4da3367db 100644 --- a/Sources/BranchSDK/BNCServerInterface.m +++ b/Sources/BranchSDK/BNCServerInterface.m @@ -61,6 +61,8 @@ - (void)postRequest:(NSDictionary *)post url:(NSString *)url key:(NSString *)key - (void)postRequest:(NSDictionary *)post url:(NSString *)url retryNumber:(NSInteger)retryNumber key:(NSString *)key callback:(BNCServerCallback)callback { + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"retryNumber %ld", retryNumber] error:nil]; + // TODO: confirm it's ok to send full URL instead of with the domain trimmed off self.requestEndpoint = url; NSURLRequest *request = [self preparePostRequest:post url:url key:key retryNumber:retryNumber]; @@ -139,7 +141,8 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN // Drops non-linking requests when tracking is disabled if (Branch.trackingDisabled) { NSString *endpoint = request.URL.absoluteString; - + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Tracking is disabled, checking if %@ is linking request.", endpoint] error:nil]; + if (![self isLinkingRelatedRequest:endpoint]) { [[BNCPreferenceHelper sharedInstance] clearTrackingInformation]; NSError *error = [NSError branchErrorWithCode:BNCTrackingDisabledError]; @@ -290,6 +293,10 @@ - (BNCServerResponse *)processServerResponse:(NSURLResponse *)response data:(NSD NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; NSString *requestId = httpResponse.allHeaderFields[@"X-Branch-Request-Id"]; + if ([[BranchLogger shared] shouldLog:BranchLogLevelVerbose]) { + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Processing response %@", requestId] error:nil]; + } + if (!error) { serverResponse.statusCode = @([httpResponse statusCode]); serverResponse.data = [BNCEncodingUtils decodeJsonDataToDictionary:data]; diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 97a7383b9..4323d283e 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -504,6 +504,8 @@ + (BOOL)trackingDisabled { + (void)setTrackingDisabled:(BOOL)disabled { @synchronized(self) { + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"setTrackingDisabled to %d", disabled] error:nil]; + BOOL currentSetting = self.trackingDisabled; if (!!currentSetting == !!disabled) return; @@ -515,6 +517,8 @@ + (void)setTrackingDisabled:(BOOL)disabled { Branch *branch = Branch.getInstance; [branch clearNetworkQueue]; branch.initializationStatus = BNCInitStatusUninitialized; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", branch.initializationStatus] error:nil]; + [branch.linkCache clear]; // Release the lock in case it's locked: [BranchOpenRequest releaseOpenResponseLock]; @@ -668,10 +672,12 @@ - (BOOL)handleDeepLink:(NSURL *)url { } - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier { + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Handle deep link %@", url] error:nil]; // we've been resetting the session on all deeplinks for quite some time // this allows foreground links to callback self.initializationStatus = BNCInitStatusUninitialized; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil]; //Check the referring url/uri for query parameters and save them BNCReferringURLUtility *utility = [BNCReferringURLUtility new]; @@ -702,6 +708,8 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sceneIdentifier { BOOL handled = NO; self.preferenceHelper.referringURL = nil; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set referringURL to %@", self.preferenceHelper.referringURL] error:nil]; + if (url && ![url isEqual:[NSNull null]]) { NSString *urlScheme = [url scheme]; @@ -712,12 +720,14 @@ - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sce if (urlScheme && [scheme isEqualToString:urlScheme]) { self.preferenceHelper.externalIntentURI = [url absoluteString]; self.preferenceHelper.referringURL = [url absoluteString]; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Allowed scheme list, set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil]; break; } } } else { self.preferenceHelper.externalIntentURI = [url absoluteString]; self.preferenceHelper.referringURL = [url absoluteString]; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil]; } NSString *query = [url fragment]; @@ -762,6 +772,7 @@ - (BOOL)handleUniversalDeepLink_private:(NSString*)urlString sceneIdentifier:(NS if (urlString.length) { self.preferenceHelper.universalLinkUrl = urlString; self.preferenceHelper.referringURL = urlString; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set universalLinkUrl and referringURL to %@", urlString] error:nil]; } [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:urlString]; @@ -1699,16 +1710,25 @@ - (void)applicationDidBecomeActive { dispatch_async(self.isolationQueue, ^(){ // if necessary, creates a new organic open BOOL installOrOpenInQueue = [self.requestQueue containsInstallOrOpen]; + + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationDidBecomeActive installOrOpenInQueue %d", installOrOpenInQueue] error:nil]; + if (!Branch.trackingDisabled && self.initializationStatus != BNCInitStatusInitialized && !installOrOpenInQueue) { + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationDidBecomeActive trackingDisabled %d initializationStatus %d installOrOpenInQueue %d", Branch.trackingDisabled, self.initializationStatus, installOrOpenInQueue] error:nil]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil]; } }); } - (void)applicationWillResignActive { + [[BranchLogger shared] logVerbose:@"applicationWillResignActive" error:nil]; + dispatch_async(self.isolationQueue, ^(){ if (!Branch.trackingDisabled) { self.initializationStatus = BNCInitStatusUninitialized; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationWillResignActive initializationStatus %ld", self.initializationStatus] error:nil]; + [self.requestQueue persistImmediately]; [BranchOpenRequest setWaitNeededForOpenResponseLock]; } @@ -1842,6 +1862,8 @@ - (void)processNextQueueItem { self.networkCount = 1; dispatch_semaphore_signal(self.processing_sema); BNCServerRequest *req = [self.requestQueue peek]; + + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Processing %@", req]error:nil]; if (req) { @@ -2035,6 +2057,8 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS } self.initializationStatus = BNCInitStatusInitializing; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil]; + [self processNextQueueItem]; }); } @@ -2044,6 +2068,8 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS - (void)handleInitSuccessAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier { self.initializationStatus = BNCInitStatusInitialized; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil]; + NSDictionary *latestReferringParams = [self getLatestReferringParams]; if ([latestReferringParams[@"_branch_validate"] isEqualToString:@"060514"]) { @@ -2260,6 +2286,7 @@ - (void)presentSharingViewController:(UIViewController