From b9a27c3d95f4129b2294606417abfc3d2a780e3d Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Mon, 5 Feb 2024 17:15:38 -0800 Subject: [PATCH 01/16] Created BranchLogger --- .../Branch-SDK-Tests/BranchLoggerTests.m | 110 ++++++++++++++++++ .../Branch-TestBed.xcodeproj/project.pbxproj | 12 ++ Branch-TestBed/Branch-TestBed/AppDelegate.m | 15 ++- BranchSDK/BNCNetworkService.m | 5 +- BranchSDK/BNCServerInterface.m | 4 +- BranchSDK/Branch.h | 13 +-- BranchSDK/Branch.m | 18 ++- BranchSDK/BranchLogger.h | 39 +++++++ BranchSDK/BranchLogger.m | 91 +++++++++++++++ 9 files changed, 279 insertions(+), 28 deletions(-) create mode 100644 Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m create mode 100644 BranchSDK/BranchLogger.h create mode 100644 BranchSDK/BranchLogger.m diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m new file mode 100644 index 000000000..47bd130b1 --- /dev/null +++ b/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m @@ -0,0 +1,110 @@ +// +// BranchLoggerTests.m +// Branch-SDK-Tests +// +// Created by Nipun Singh on 2/5/24. +// Copyright © 2024 Branch, Inc. All rights reserved. +// + +#import +#import "BranchLogger.h" +#import "Branch.h" + +@interface BranchLoggerTests : XCTestCase +@end + +@implementation BranchLoggerTests + +- (void)setUp { + [super setUp]; + [BranchLogger shared].loggingEnabled = NO; + [BranchLogger shared].logCallback = nil; +} + +- (void)tearDown { + [BranchLogger shared].loggingEnabled = NO; + [BranchLogger shared].logCallback = nil; + [super tearDown]; +} + +- (void)testEnableLoggingSetsCorrectDefaultLevel { + [[Branch getInstance] enableLogging]; + XCTAssertEqual([BranchLogger shared].logLevelThreshold, BranchLogLevelDebug, "Default log level should be Debug."); +} + +- (void)testLogLevelThresholdBlocksLowerLevels { + [[Branch getInstance] enableLoggingAtLevel:BranchLogLevelDebug]; + XCTestExpectation *expectation = [self expectationWithDescription:@"Log callback expectation for message that should pass the threshold"]; + + [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + if ([message isEqualToString:@"[BranchSDK][Debug] This message should trigger the log callback."] && logLevel >= BranchLogLevelDebug) { + [expectation fulfill]; + } + }; + + [[BranchLogger shared] logVerbose:@"This verbose message should not trigger the log callback."]; + [[BranchLogger shared] logDebug:@"This message should trigger the log callback."]; + + [self waitForExpectationsWithTimeout:1 handler:nil]; +} + +- (void)testLogCallbackExecutesWithCorrectParameters { + XCTestExpectation *expectation = [self expectationWithDescription:@"Log callback expectation"]; + NSString *expectedMessage = @"[BranchSDK][Info] Test message"; + BranchLogLevel expectedLevel = BranchLogLevelInfo; + + [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + XCTAssertEqualObjects(message, expectedMessage, "Logged message does not match expected message."); + XCTAssertEqual(logLevel, expectedLevel, "Logged level does not match expected level."); + XCTAssertNil(error, "Error should be nil."); + [expectation fulfill]; + }; + + [[Branch getInstance] enableLoggingAtLevel:BranchLogLevelInfo]; + [[BranchLogger shared] logInfo:@"Test message"]; + + [self waitForExpectationsWithTimeout:1 handler:nil]; +} + +- (void)testLogLevelSpecificityFiltersLowerLevels { + [[Branch getInstance] enableLoggingAtLevel:BranchLogLevelWarning]; + + XCTestExpectation *verboseExpectation = [self expectationWithDescription:@"Verbose log callback"]; + verboseExpectation.inverted = YES; + XCTestExpectation *errorExpectation = [self expectationWithDescription:@"Error log callback"]; + + __block NSUInteger callbackCount = 0; + [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + if (logLevel == BranchLogLevelVerbose) { + [verboseExpectation fulfill]; + } else if (logLevel == BranchLogLevelError) { + [errorExpectation fulfill]; + } + callbackCount++; + }; + + [[BranchLogger shared] logVerbose:@"This should not be logged due to log level threshold."]; + [[BranchLogger shared] logError:@"This should be logged" error:nil]; + + [self waitForExpectations:@[verboseExpectation, errorExpectation] timeout:2]; + XCTAssertEqual(callbackCount, 1, "Only one log callback should have been invoked."); +} + +- (void)testErrorLoggingIncludesErrorDetails { + [[Branch getInstance] enableLogging]; + XCTestExpectation *expectation = [self expectationWithDescription:@"Error log includes error details"]; + + NSError *testError = [NSError errorWithDomain:@"TestDomain" code:42 userInfo:@{NSLocalizedDescriptionKey: @"Test error description"}]; + [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + if ([message containsString:@"Test error description"] && error == testError) { + [expectation fulfill]; + } + }; + + [[BranchLogger shared] logError:@"Testing error logging" error:testError]; + + [self waitForExpectationsWithTimeout:1 handler:nil]; +} + + +@end diff --git a/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj b/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj index f5431f7e1..d9fd0500d 100644 --- a/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj +++ b/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj @@ -228,6 +228,9 @@ C1614D56285BC8A00098946B /* LinkPresentation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1614D55285BC8A00098946B /* LinkPresentation.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; C1614D5C285BD4AF0098946B /* BranchPluginSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = C1614D5A285BD4AF0098946B /* BranchPluginSupport.h */; }; C1614D5D285BD4AF0098946B /* BranchPluginSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = C1614D5B285BD4AF0098946B /* BranchPluginSupport.m */; }; + C16B975B2B6C21C900FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B975A2B6C21C900FB0631 /* BranchLogger.h */; }; + C16B975D2B6C21DC00FB0631 /* BranchLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B975C2B6C21DC00FB0631 /* BranchLogger.m */; }; + C16B975F2B716C4700FB0631 /* BranchLoggerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B975E2B716C4700FB0631 /* BranchLoggerTests.m */; }; C17394602A8AEE0E006068F2 /* BNCProductCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = C173945F2A8AEE0E006068F2 /* BNCProductCategory.m */; }; C17394612A8C20FD006068F2 /* BNCProductCategory.h in Headers */ = {isa = PBXBuildFile; fileRef = C173945E2A8AEDFB006068F2 /* BNCProductCategory.h */; settings = {ATTRIBUTES = (Public, ); }; }; C17394642A8C228D006068F2 /* BNCCurrency.m in Sources */ = {isa = PBXBuildFile; fileRef = C17394632A8C228D006068F2 /* BNCCurrency.m */; }; @@ -541,6 +544,9 @@ C1614D55285BC8A00098946B /* LinkPresentation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LinkPresentation.framework; path = System/Library/Frameworks/LinkPresentation.framework; sourceTree = SDKROOT; }; C1614D5A285BD4AF0098946B /* BranchPluginSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchPluginSupport.h; sourceTree = ""; }; C1614D5B285BD4AF0098946B /* BranchPluginSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchPluginSupport.m; sourceTree = ""; }; + C16B975A2B6C21C900FB0631 /* BranchLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BranchLogger.h; sourceTree = ""; }; + C16B975C2B6C21DC00FB0631 /* BranchLogger.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BranchLogger.m; sourceTree = ""; }; + C16B975E2B716C4700FB0631 /* BranchLoggerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BranchLoggerTests.m; sourceTree = ""; }; C173945E2A8AEDFB006068F2 /* BNCProductCategory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCProductCategory.h; sourceTree = ""; }; C173945F2A8AEE0E006068F2 /* BNCProductCategory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCProductCategory.m; sourceTree = ""; }; C17394622A8C2282006068F2 /* BNCCurrency.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCCurrency.h; sourceTree = ""; }; @@ -685,6 +691,7 @@ C15CC9DF2ABCF8C8003CC339 /* BranchActivityItemTests.m */, C17DAF7A2AC20C2000B16B1A /* BranchClassTests.m */, C15CC9DD2ABCB549003CC339 /* BNCCurrencyTests.m */, + C16B975E2B716C4700FB0631 /* BranchLoggerTests.m */, ); path = "Branch-SDK-Tests"; sourceTree = ""; @@ -861,6 +868,8 @@ 7E30BCF31A71EEEE00AC7402 /* BNCLinkData.m */, 4DA577151E67B1D600A43BDD /* BNCLog.h */, 4DA577161E67B1D600A43BDD /* BNCLog.m */, + C16B975A2B6C21C900FB0631 /* BranchLogger.h */, + C16B975C2B6C21DC00FB0631 /* BranchLogger.m */, 5F92B23D238486E200CA909B /* BNCNetworkInterface.h */, 5F92B23E238486E200CA909B /* BNCNetworkInterface.m */, 5F38020224DCC2E600E6FAFD /* BNCNetworkService.h */, @@ -1030,6 +1039,7 @@ 5F38022524DCC2E800E6FAFD /* BranchLATDRequest.h in Headers */, 4DCAC8051F426F7C00405D1D /* BNCDeviceInfo.h in Headers */, 4DCAC8061F426F7C00405D1D /* BNCEncodingUtils.h in Headers */, + C16B975B2B6C21C900FB0631 /* BranchLogger.h in Headers */, 5F92B23123834AFD00CA909B /* BNCReachability.h in Headers */, 4DCAC80E1F426F7C00405D1D /* BNCSystemObserver.h in Headers */, C10C61AD28248E5A00761D7E /* BNCQRCodeCache.h in Headers */, @@ -1344,6 +1354,7 @@ 466B586A1B17779C00A69EDE /* BNCLinkCache.m in Sources */, 4D7881F7209CF28F002B750F /* BNCThreads.m in Sources */, 5F892EBE2361157E0023AEC1 /* NSError+Branch.m in Sources */, + C16B975D2B6C21DC00FB0631 /* BranchLogger.m in Sources */, 9A2B7DD61FEC3BAF00CD188B /* Branch+Validator.m in Sources */, 5FE693F82405E91500E3AEE2 /* BNCCallbackMap.m in Sources */, 5F92B240238486E200CA909B /* BNCNetworkInterface.m in Sources */, @@ -1433,6 +1444,7 @@ 4D1683AC2098C902008819E3 /* BranchInstallRequestTests.m in Sources */, 4D1683C72098C902008819E3 /* BNCCrashlyticsWrapperTests.m in Sources */, 5FDF91592581CDF4009BE5A3 /* BNCPartnerParametersTests.m in Sources */, + C16B975F2B716C4700FB0631 /* BranchLoggerTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index 09925169f..305a295e9 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -23,8 +23,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { appDelegate = self; - BNCLogSetOutputFunction(APPLogHookFunction); - BNCLogSetDisplayLevel(BNCLogLevelAll); /* Set Branch.useTestBranchKey = YES; to have Branch use the test key that's in the app's @@ -38,10 +36,15 @@ - (BOOL)application:(UIApplication *)application // test pre init support //[self testDispatchToIsolationQueue:branch] - // Comment out (for match guarantee testing) / or un-comment to toggle debugging: - // Note: Unit tests will fail if 'setDebug' is set. - // [branch setDebug]; - [branch enableLogging]; + [branch enableLoggingAtLevel:BranchLogLevelVerbose]; +// [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { +// // Handle the log message and error here. For example, printing to the console: +// if (error) { +// NSLog(@"[BranchLog] Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription); +// } else { +// NSLog(@"[BranchLog] Level: %lu, Message: %@", (unsigned long)logLevel, message); +// } +// }; // Comment out in production. Un-comment to test your Branch SDK Integration: //[branch validateSDKIntegration]; diff --git a/BranchSDK/BNCNetworkService.m b/BranchSDK/BNCNetworkService.m index 48b7edba0..255350470 100644 --- a/BranchSDK/BNCNetworkService.m +++ b/BranchSDK/BNCNetworkService.m @@ -10,6 +10,7 @@ #import "BNCEncodingUtils.h" #import "BNCLog.h" #import "NSError+Branch.h" +#import "BranchLogger.h" #pragma mark BNCNetworkOperation @@ -204,7 +205,9 @@ - (void) startOperation:(BNCNetworkOperation*)operation { if (operation.completionBlock) operation.completionBlock(operation); }]; - BNCLogDebug([NSString stringWithFormat:@"Network start operation %@.", operation.request.URL]); + + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Network start operation %@.", operation.request.URL]]; + [operation.sessionTask resume]; } diff --git a/BranchSDK/BNCServerInterface.m b/BranchSDK/BNCServerInterface.m index ec652d406..eaa95e182 100644 --- a/BranchSDK/BNCServerInterface.m +++ b/BranchSDK/BNCServerInterface.m @@ -16,6 +16,7 @@ #import "Branch.h" #import "BNCSKAdNetwork.h" #import "BNCReferringURLUtility.h" +#import "BranchLogger.h" @interface BNCServerInterface () @property (copy, nonatomic) NSString *requestEndpoint; @@ -329,8 +330,9 @@ - (BNCServerResponse *)processServerResponse:(NSURLResponse *)response data:(NSD serverResponse.data = error.userInfo; serverResponse.requestId = requestId; } + + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Server returned: %@.", serverResponse]]; - BNCLogDebug([NSString stringWithFormat:@"Server returned: %@.", serverResponse]); return serverResponse; } diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index d4ab71e10..322b09e28 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -39,6 +39,7 @@ #import "BNCServerInterface.h" #import "BNCServerRequestQueue.h" +#import "BranchLogger.h" // Not used by Branch singleton public API //#import "BranchEvent.h" //#import "BranchScene.h" @@ -564,9 +565,10 @@ extern NSString * __nonnull const BNCSpotlightFeature; ///-------------------- /** - Enable debug messages to NSLog. + Enable debug messages to os_log. */ - (void)enableLogging; +- (void)enableLoggingAtLevel:(BranchLogLevel)logLevel; /** Send requests to EU endpoints. @@ -575,15 +577,6 @@ extern NSString * __nonnull const BNCSpotlightFeature; */ - (void)useEUEndpoints; -/** - setDebug is deprecated and all functionality has been disabled. - - If you wish to enable logging, please invoke enableLogging. - - If you wish to simulate installs, please see add a Test Device (https://help.branch.io/using-branch/docs/adding-test-devices) then reset your test device's data (https://help.branch.io/using-branch/docs/adding-test-devices#section-resetting-your-test-device-data). - */ -- (void)setDebug __attribute__((deprecated(("setDebug is replaced by enableLogging and test devices. https://help.branch.io/using-branch/docs/adding-test-devices")))); - /** @brief Use the `validateSDKIntegration` method as a debugging aid to assure that you've integrated the Branch SDK correctly. diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index da80d47ee..4f1ce5ce2 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -43,6 +43,7 @@ #import "UIViewController+Branch.h" #import "BNCReferringURLUtility.h" #import "BNCServerAPI.h" +#import "BranchLogger.h" #if !TARGET_OS_TV #import "BNCUserAgentCollector.h" @@ -419,20 +420,17 @@ + (BOOL)branchKeyIsSet { } - (void)enableLogging { - BNCLogSetDisplayLevel(BNCLogLevelDebug); + [self enableLoggingAtLevel:BranchLogLevelDebug]; } -- (void)useEUEndpoints { - [BNCServerAPI sharedInstance].useEUServers = YES; +- (void)enableLoggingAtLevel:(BranchLogLevel)logLevel { + BranchLogger *logger = [BranchLogger shared]; + logger.loggingEnabled = YES; + logger.logLevelThreshold = logLevel; } -- (void)setDebug { - NSLog(@"Branch setDebug is deprecated and all functionality has been disabled. " - "If you wish to enable logging, please invoke enableLogging. " - "If you wish to simulate installs, please see add a Test Device " - "(https://help.branch.io/using-branch/docs/adding-test-devices) " - "then reset your test device's data " - "(https://help.branch.io/using-branch/docs/adding-test-devices#section-resetting-your-test-device-data)."); +- (void)useEUEndpoints { + [BNCServerAPI sharedInstance].useEUServers = YES; } - (void)validateSDKIntegration { diff --git a/BranchSDK/BranchLogger.h b/BranchSDK/BranchLogger.h new file mode 100644 index 000000000..6f9a6e254 --- /dev/null +++ b/BranchSDK/BranchLogger.h @@ -0,0 +1,39 @@ +// +// BranchLogger.h +// Branch +// +// Created by Nipun Singh on 2/1/24. +// Copyright © 2024 Branch, Inc. All rights reserved. +// + +#import + +typedef NS_ENUM(NSUInteger, BranchLogLevel) { + BranchLogLevelVerbose, + BranchLogLevelDebug, + BranchLogLevelInfo, + BranchLogLevelWarning, + BranchLogLevelError, +}; + +typedef void(^BranchLogCallback)(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error); + +NS_ASSUME_NONNULL_BEGIN + +@interface BranchLogger : NSObject + +@property (nonatomic, assign) BOOL loggingEnabled; +@property (nonatomic, copy, nullable) BranchLogCallback logCallback; +@property (nonatomic, assign) BranchLogLevel logLevelThreshold; + ++ (instancetype _Nonnull)shared; + +- (void)logError:(NSString * _Nonnull)message error:(NSError * _Nullable)error; +- (void)logWarning:(NSString * _Nonnull)message; +- (void)logInfo:(NSString * _Nonnull)message; +- (void)logDebug:(NSString * _Nonnull)message; +- (void)logVerbose:(NSString * _Nonnull)message; + +@end + +NS_ASSUME_NONNULL_END diff --git a/BranchSDK/BranchLogger.m b/BranchSDK/BranchLogger.m new file mode 100644 index 000000000..4a0bc6524 --- /dev/null +++ b/BranchSDK/BranchLogger.m @@ -0,0 +1,91 @@ +// +// BranchLogger.m +// Branch +// +// Created by Nipun Singh on 2/1/24. +// Copyright © 2024 Branch, Inc. All rights reserved. +// + +#import "BranchLogger.h" +#import + +@implementation BranchLogger + +static BranchLogLevel _logLevelThreshold = BranchLogLevelDebug; + ++ (instancetype)shared { + static BranchLogger *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[BranchLogger alloc] init]; + sharedInstance.loggingEnabled = NO; + sharedInstance.logLevelThreshold = BranchLogLevelDebug; + }); + return sharedInstance; +} + +- (void)logError:(NSString *)message error:(NSError *_Nullable)error { + [self logMessage:message withLevel:BranchLogLevelError error:error]; +} + +- (void)logWarning:(NSString *)message { + [self logMessage:message withLevel:BranchLogLevelWarning error:nil]; +} + +- (void)logInfo:(NSString *)message { + [self logMessage:message withLevel:BranchLogLevelInfo error:nil]; +} + +- (void)logDebug:(NSString *)message { + [self logMessage:message withLevel:BranchLogLevelDebug error:nil]; +} + +- (void)logVerbose:(NSString *)message { + [self logMessage:message withLevel:BranchLogLevelVerbose error:nil]; +} + +- (void)logMessage:(NSString *)message withLevel:(BranchLogLevel)level error:(NSError *_Nullable)error { + if (!self.loggingEnabled || message.length == 0 || level < self.logLevelThreshold) { + return; + } + + NSString *logLevelString = [self stringForLogLevel:level]; + NSString *logTag = [NSString stringWithFormat:@"[BranchSDK][%@]", logLevelString]; + NSMutableString *fullMessage = [NSMutableString stringWithFormat:@"%@ %@", logTag, message]; + + if (error) { + [fullMessage appendFormat:@", Error: %@ (Domain: %@, Code: %ld)", error.localizedDescription, error.domain, (long)error.code]; + } + + if (self.logCallback) { + self.logCallback(fullMessage, level, error); + } else { + os_log_t log = os_log_create("io.branch.sdk", "BranchSDK"); + os_log_type_t osLogType = [self osLogTypeForBranchLogLevel:level]; + os_log_with_type(log, osLogType, "%{public}@", fullMessage); + } +} + +- (os_log_type_t)osLogTypeForBranchLogLevel:(BranchLogLevel)level { + switch (level) { + case BranchLogLevelError: return OS_LOG_TYPE_FAULT; + case BranchLogLevelWarning: return OS_LOG_TYPE_ERROR; + case BranchLogLevelInfo: return OS_LOG_TYPE_INFO; + case BranchLogLevelDebug: return OS_LOG_TYPE_DEBUG; + case BranchLogLevelVerbose: return OS_LOG_TYPE_DEFAULT; + default: return OS_LOG_TYPE_DEFAULT; + } +} + +- (NSString *)stringForLogLevel:(BranchLogLevel)level { + switch (level) { + case BranchLogLevelVerbose: return @"Verbose"; + case BranchLogLevelDebug: return @"Debug"; + case BranchLogLevelInfo: return @"Info"; + case BranchLogLevelWarning: return @"Warning"; + case BranchLogLevelError: return @"Error"; + default: return @"Unknown"; + } +} + +@end From b17ea2b0338b7fbedf328e31f5bef0f8e57b9862 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Tue, 6 Feb 2024 10:50:00 -0800 Subject: [PATCH 02/16] Added callingClass helper method --- .../Branch-SDK-Tests/BranchLoggerTests.m | 4 ++-- BranchSDK/BranchLogger.m | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m index 47bd130b1..b403ee6fd 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m @@ -37,7 +37,7 @@ - (void)testLogLevelThresholdBlocksLowerLevels { XCTestExpectation *expectation = [self expectationWithDescription:@"Log callback expectation for message that should pass the threshold"]; [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { - if ([message isEqualToString:@"[BranchSDK][Debug] This message should trigger the log callback."] && logLevel >= BranchLogLevelDebug) { + if ([message isEqualToString:@"[BranchSDK][Debug][BranchLoggerTests testLogLevelThresholdBlocksLowerLevels] This message should trigger the log callback."] && logLevel >= BranchLogLevelDebug) { [expectation fulfill]; } }; @@ -50,7 +50,7 @@ - (void)testLogLevelThresholdBlocksLowerLevels { - (void)testLogCallbackExecutesWithCorrectParameters { XCTestExpectation *expectation = [self expectationWithDescription:@"Log callback expectation"]; - NSString *expectedMessage = @"[BranchSDK][Info] Test message"; + NSString *expectedMessage = @"[BranchSDK][Info][BranchLoggerTests testLogCallbackExecutesWithCorrectParameters] Test message"; BranchLogLevel expectedLevel = BranchLogLevelInfo; [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { diff --git a/BranchSDK/BranchLogger.m b/BranchSDK/BranchLogger.m index 4a0bc6524..63ebbc72c 100644 --- a/BranchSDK/BranchLogger.m +++ b/BranchSDK/BranchLogger.m @@ -49,9 +49,10 @@ - (void)logMessage:(NSString *)message withLevel:(BranchLogLevel)level error:(NS return; } + NSString *callerDetails = [self callingClass]; NSString *logLevelString = [self stringForLogLevel:level]; NSString *logTag = [NSString stringWithFormat:@"[BranchSDK][%@]", logLevelString]; - NSMutableString *fullMessage = [NSMutableString stringWithFormat:@"%@ %@", logTag, message]; + NSMutableString *fullMessage = [NSMutableString stringWithFormat:@"%@%@ %@", logTag, callerDetails, message]; if (error) { [fullMessage appendFormat:@", Error: %@ (Domain: %@, Code: %ld)", error.localizedDescription, error.domain, (long)error.code]; @@ -66,6 +67,7 @@ - (void)logMessage:(NSString *)message withLevel:(BranchLogLevel)level error:(NS } } +//MARK: Helper Methods - (os_log_type_t)osLogTypeForBranchLogLevel:(BranchLogLevel)level { switch (level) { case BranchLogLevelError: return OS_LOG_TYPE_FAULT; @@ -88,4 +90,18 @@ - (NSString *)stringForLogLevel:(BranchLogLevel)level { } } +- (NSString *)callingClass { + NSArray *stackSymbols = [NSThread callStackSymbols]; + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\[([^\\]]+)\\]" options:0 error:nil]; + if (stackSymbols.count > 3 && regex) { + NSString *callSite = stackSymbols[3]; + NSTextCheckingResult *match = [regex firstMatchInString:callSite options:0 range:NSMakeRange(0, [callSite length])]; + if (match && match.range.location != NSNotFound) { + NSString *callerDetails = [callSite substringWithRange:[match rangeAtIndex:0]]; + return callerDetails; + } + } + return @""; +} + @end From f49e64331d5b380accb3a80e3c581fa80f2c0fcc Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Tue, 6 Feb 2024 11:05:46 -0800 Subject: [PATCH 03/16] Update BranchLogger.m --- BranchSDK/BranchLogger.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BranchSDK/BranchLogger.m b/BranchSDK/BranchLogger.m index 63ebbc72c..6e869dd46 100644 --- a/BranchSDK/BranchLogger.m +++ b/BranchSDK/BranchLogger.m @@ -63,7 +63,7 @@ - (void)logMessage:(NSString *)message withLevel:(BranchLogLevel)level error:(NS } else { os_log_t log = os_log_create("io.branch.sdk", "BranchSDK"); os_log_type_t osLogType = [self osLogTypeForBranchLogLevel:level]; - os_log_with_type(log, osLogType, "%{public}@", fullMessage); + os_log_with_type(log, osLogType, "%{private}@", fullMessage); } } From 18b5820cd365385c77d9270b4640380b07917fad Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 7 Feb 2024 14:16:00 -0800 Subject: [PATCH 04/16] Added options for disabling callerDetails --- .../Branch-SDK-Tests/BranchLoggerTests.m | 53 +++++++++---------- BranchSDK/BranchLogger.h | 3 ++ BranchSDK/BranchLogger.m | 16 +++++- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m index b403ee6fd..38d4f1dfa 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m @@ -15,35 +15,26 @@ @interface BranchLoggerTests : XCTestCase @implementation BranchLoggerTests -- (void)setUp { - [super setUp]; - [BranchLogger shared].loggingEnabled = NO; - [BranchLogger shared].logCallback = nil; -} - -- (void)tearDown { - [BranchLogger shared].loggingEnabled = NO; - [BranchLogger shared].logCallback = nil; - [super tearDown]; -} - - (void)testEnableLoggingSetsCorrectDefaultLevel { [[Branch getInstance] enableLogging]; XCTAssertEqual([BranchLogger shared].logLevelThreshold, BranchLogLevelDebug, "Default log level should be Debug."); } - (void)testLogLevelThresholdBlocksLowerLevels { - [[Branch getInstance] enableLoggingAtLevel:BranchLogLevelDebug]; + BranchLogger *logger = [BranchLogger new]; + logger.loggingEnabled = true; + logger.logLevelThreshold = BranchLogLevelDebug; + XCTestExpectation *expectation = [self expectationWithDescription:@"Log callback expectation for message that should pass the threshold"]; - [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + logger.logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { if ([message isEqualToString:@"[BranchSDK][Debug][BranchLoggerTests testLogLevelThresholdBlocksLowerLevels] This message should trigger the log callback."] && logLevel >= BranchLogLevelDebug) { [expectation fulfill]; } }; - [[BranchLogger shared] logVerbose:@"This verbose message should not trigger the log callback."]; - [[BranchLogger shared] logDebug:@"This message should trigger the log callback."]; + [logger logVerbose:@"This verbose message should not trigger the log callback."]; + [logger logDebug:@"This message should trigger the log callback."]; [self waitForExpectationsWithTimeout:1 handler:nil]; } @@ -53,28 +44,33 @@ - (void)testLogCallbackExecutesWithCorrectParameters { NSString *expectedMessage = @"[BranchSDK][Info][BranchLoggerTests testLogCallbackExecutesWithCorrectParameters] Test message"; BranchLogLevel expectedLevel = BranchLogLevelInfo; - [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + BranchLogger *logger = [BranchLogger new]; + + logger.logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { XCTAssertEqualObjects(message, expectedMessage, "Logged message does not match expected message."); XCTAssertEqual(logLevel, expectedLevel, "Logged level does not match expected level."); XCTAssertNil(error, "Error should be nil."); [expectation fulfill]; }; - - [[Branch getInstance] enableLoggingAtLevel:BranchLogLevelInfo]; - [[BranchLogger shared] logInfo:@"Test message"]; + + logger.loggingEnabled = YES; + logger.logLevelThreshold = BranchLogLevelInfo; + [logger logInfo:@"Test message"]; [self waitForExpectationsWithTimeout:1 handler:nil]; } - (void)testLogLevelSpecificityFiltersLowerLevels { - [[Branch getInstance] enableLoggingAtLevel:BranchLogLevelWarning]; + BranchLogger *logger = [BranchLogger new]; + logger.loggingEnabled = YES; + logger.logLevelThreshold = BranchLogLevelWarning; XCTestExpectation *verboseExpectation = [self expectationWithDescription:@"Verbose log callback"]; verboseExpectation.inverted = YES; XCTestExpectation *errorExpectation = [self expectationWithDescription:@"Error log callback"]; __block NSUInteger callbackCount = 0; - [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + logger.logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { if (logLevel == BranchLogLevelVerbose) { [verboseExpectation fulfill]; } else if (logLevel == BranchLogLevelError) { @@ -83,28 +79,29 @@ - (void)testLogLevelSpecificityFiltersLowerLevels { callbackCount++; }; - [[BranchLogger shared] logVerbose:@"This should not be logged due to log level threshold."]; - [[BranchLogger shared] logError:@"This should be logged" error:nil]; + [logger logVerbose:@"This should not be logged due to log level threshold."]; + [logger logError:@"This should be logged" error:nil]; [self waitForExpectations:@[verboseExpectation, errorExpectation] timeout:2]; XCTAssertEqual(callbackCount, 1, "Only one log callback should have been invoked."); } - (void)testErrorLoggingIncludesErrorDetails { - [[Branch getInstance] enableLogging]; + BranchLogger *logger = [BranchLogger new]; + logger.loggingEnabled = YES; + XCTestExpectation *expectation = [self expectationWithDescription:@"Error log includes error details"]; NSError *testError = [NSError errorWithDomain:@"TestDomain" code:42 userInfo:@{NSLocalizedDescriptionKey: @"Test error description"}]; - [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + logger.logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { if ([message containsString:@"Test error description"] && error == testError) { [expectation fulfill]; } }; - [[BranchLogger shared] logError:@"Testing error logging" error:testError]; + [logger logError:@"Testing error logging" error:testError]; [self waitForExpectationsWithTimeout:1 handler:nil]; } - @end diff --git a/BranchSDK/BranchLogger.h b/BranchSDK/BranchLogger.h index 6f9a6e254..70c6e55b1 100644 --- a/BranchSDK/BranchLogger.h +++ b/BranchSDK/BranchLogger.h @@ -23,11 +23,14 @@ NS_ASSUME_NONNULL_BEGIN @interface BranchLogger : NSObject @property (nonatomic, assign) BOOL loggingEnabled; +@property (nonatomic, assign) BOOL includeCallerDetails; @property (nonatomic, copy, nullable) BranchLogCallback logCallback; @property (nonatomic, assign) BranchLogLevel logLevelThreshold; + (instancetype _Nonnull)shared; +- (void)disableCallerDetails; + - (void)logError:(NSString * _Nonnull)message error:(NSError * _Nullable)error; - (void)logWarning:(NSString * _Nonnull)message; - (void)logInfo:(NSString * _Nonnull)message; diff --git a/BranchSDK/BranchLogger.m b/BranchSDK/BranchLogger.m index 6e869dd46..e85a16fad 100644 --- a/BranchSDK/BranchLogger.m +++ b/BranchSDK/BranchLogger.m @@ -11,7 +11,14 @@ @implementation BranchLogger -static BranchLogLevel _logLevelThreshold = BranchLogLevelDebug; +- (instancetype)init { + if ((self = [super init])) { + _loggingEnabled = NO; + _logLevelThreshold = BranchLogLevelDebug; + _includeCallerDetails = YES; + } + return self; +} + (instancetype)shared { static BranchLogger *sharedInstance = nil; @@ -20,10 +27,15 @@ + (instancetype)shared { sharedInstance = [[BranchLogger alloc] init]; sharedInstance.loggingEnabled = NO; sharedInstance.logLevelThreshold = BranchLogLevelDebug; + sharedInstance.includeCallerDetails = YES; }); return sharedInstance; } +- (void)disableCallerDetails { + self.includeCallerDetails = NO; +} + - (void)logError:(NSString *)message error:(NSError *_Nullable)error { [self logMessage:message withLevel:BranchLogLevelError error:error]; } @@ -49,7 +61,7 @@ - (void)logMessage:(NSString *)message withLevel:(BranchLogLevel)level error:(NS return; } - NSString *callerDetails = [self callingClass]; + NSString *callerDetails = self.includeCallerDetails ? [self callingClass] : @""; NSString *logLevelString = [self stringForLogLevel:level]; NSString *logTag = [NSString stringWithFormat:@"[BranchSDK][%@]", logLevelString]; NSMutableString *fullMessage = [NSMutableString stringWithFormat:@"%@%@ %@", logTag, callerDetails, message]; From e5aa03effff700612be4020e0f8a80732231a547 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Thu, 8 Feb 2024 12:47:47 -0800 Subject: [PATCH 05/16] Updated logs --- Branch-TestBed/Branch-SDK-Tests/BNCLogTests.m | 43 ------- Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m | 2 - .../Branch-SDK-Tests/BranchOpenRequestTests.m | 1 - .../Branch-TestBed.xcodeproj/project.pbxproj | 14 +-- Branch-TestBed/Branch-TestBed/AppDelegate.m | 5 +- .../Branch-TestBed/Branch-TestBed-Info.plist | 2 - BranchSDK/BNCAppGroupsData.m | 2 - BranchSDK/BNCApplication.m | 15 +-- BranchSDK/BNCDeviceInfo.m | 1 - BranchSDK/BNCEncodingUtils.m | 15 +-- BranchSDK/BNCKeyChain.m | 18 +-- BranchSDK/BNCLog.h | 88 -------------- BranchSDK/BNCLog.m | 109 ------------------ BranchSDK/BNCNetworkInterface.m | 8 +- BranchSDK/BNCNetworkService.m | 57 +++++---- BranchSDK/BNCPartnerParameters.m | 6 +- BranchSDK/BNCPreferenceHelper.m | 22 ++-- BranchSDK/BNCReferringURLUtility.m | 4 +- BranchSDK/BNCSKAdNetwork.m | 14 +-- BranchSDK/BNCServerInterface.m | 23 ++-- BranchSDK/BNCServerRequest.m | 6 +- BranchSDK/BNCServerRequestQueue.m | 22 ++-- BranchSDK/BNCSystemObserver.m | 4 +- BranchSDK/BNCURLFilter.m | 17 +-- BranchSDK/Branch.h | 3 - BranchSDK/Branch.m | 80 +++++-------- .../BranchCSSearchableItemAttributeSet.m | 4 +- BranchSDK/BranchContentDiscoverer.m | 4 +- BranchSDK/BranchEvent.m | 22 ++-- BranchSDK/BranchJsonConfig.m | 14 +-- BranchSDK/BranchLastAttributedTouchData.m | 4 +- BranchSDK/BranchOpenRequest.m | 37 +++--- BranchSDK/BranchPluginSupport.m | 1 - BranchSDK/BranchQRCode.m | 41 +++---- BranchSDK/BranchScene.m | 4 +- BranchSDK/BranchShareLink.m | 13 +-- BranchSDK/BranchShortUrlSyncRequest.m | 6 +- BranchSDK/BranchUniversalObject.m | 11 +- 38 files changed, 216 insertions(+), 526 deletions(-) delete mode 100644 Branch-TestBed/Branch-SDK-Tests/BNCLogTests.m delete mode 100644 BranchSDK/BNCLog.h delete mode 100644 BranchSDK/BNCLog.m diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCLogTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCLogTests.m deleted file mode 100644 index 32e6fcd82..000000000 --- a/Branch-TestBed/Branch-SDK-Tests/BNCLogTests.m +++ /dev/null @@ -1,43 +0,0 @@ -/** - @file BNCLogTests.m - @package BranchTests - @brief Tests for BNCLog. - - @author Edward Smith - @date October 2016 - @copyright Copyright © 2016 Branch. All rights reserved. -*/ - -#import -#import "BNCLog.h" - -@interface BNCLogTests : XCTestCase -@end - -@implementation BNCLogTests - -- (void)setUp { - // Put setup code here. This method is called before the invocation of each test method in the class. -} - -- (void)tearDown { - // Put teardown code here. This method is called after the invocation of each test method in the class. -} - -- (void)testLogLevelString { - XCTAssertEqual(BNCLogLevelAll, BNCLogLevelFromString(@"BNCLogLevelAll")); - XCTAssertEqual(BNCLogLevelDebugSDK, BNCLogLevelFromString(@"BNCLogLevelDebugSDK")); - XCTAssertEqual(BNCLogLevelWarning, BNCLogLevelFromString(@"BNCLogLevelWarning")); - XCTAssertEqual(BNCLogLevelNone, BNCLogLevelFromString(@"BNCLogLevelNone")); - XCTAssertEqual(BNCLogLevelMax, BNCLogLevelFromString(@"BNCLogLevelMax")); -} - -- (void)testLogLevelEnum { - XCTAssertEqualObjects(@"BNCLogLevelAll", BNCLogStringFromLogLevel(BNCLogLevelAll)); - XCTAssertEqualObjects(@"BNCLogLevelAll", BNCLogStringFromLogLevel(BNCLogLevelDebugSDK)); - XCTAssertEqualObjects(@"BNCLogLevelWarning", BNCLogStringFromLogLevel(BNCLogLevelWarning)); - XCTAssertEqualObjects(@"BNCLogLevelNone", BNCLogStringFromLogLevel(BNCLogLevelNone)); - XCTAssertEqualObjects(@"BNCLogLevelMax", BNCLogStringFromLogLevel(BNCLogLevelMax)); -} - -@end diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m b/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m index 76ab2e1d2..2afa92010 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m @@ -9,7 +9,6 @@ */ #import "BNCTestCase.h" -#import "BNCLog.h" #import "Branch.h" #import "BNCApplication+BNCTest.h" @@ -96,7 +95,6 @@ - (double) systemVersion { + (void) initialize { if (self != [BNCTestCase self]) return; - BNCLogSetDisplayLevel(BNCLogLevelAll); savedRandomizedBundleToken = [BNCPreferenceHelper sharedInstance].randomizedBundleToken; [Branch clearAll]; diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchOpenRequestTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchOpenRequestTests.m index 772f8b624..234084b81 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchOpenRequestTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchOpenRequestTests.m @@ -8,7 +8,6 @@ #import "BNCTestCase.h" #import "Branch.h" -#import "BNCLog.h" #import "BNCApplication+BNCTest.h" #import "BranchOpenRequest.h" #import "BranchConstants.h" diff --git a/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj b/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj index d9fd0500d..27b0ee6a9 100644 --- a/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj +++ b/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj @@ -42,7 +42,6 @@ 4D1683B72098C902008819E3 /* BNCTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16838D2098C901008819E3 /* BNCTestCase.m */; }; 4D1683B82098C902008819E3 /* BNCEncodingUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16838E2098C901008819E3 /* BNCEncodingUtilsTests.m */; }; 4D1683B92098C902008819E3 /* BNCSystemObserverTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16838F2098C901008819E3 /* BNCSystemObserverTests.m */; }; - 4D1683BA2098C902008819E3 /* BNCLogTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683902098C901008819E3 /* BNCLogTests.m */; }; 4D1683C02098C902008819E3 /* BranchUniversalObjectTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683962098C901008819E3 /* BranchUniversalObjectTests.m */; }; 4D1683C12098C902008819E3 /* BNCApplicationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1683972098C901008819E3 /* BNCApplicationTests.m */; }; 4D1683C62098C902008819E3 /* BranchEvent.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16839C2098C901008819E3 /* BranchEvent.Test.m */; }; @@ -66,7 +65,6 @@ 4D955CCD2035021400FB8008 /* BNCURLFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D955CCB2035021400FB8008 /* BNCURLFilter.m */; }; 4D9607F41FBF9473008AB3C2 /* UIViewController+Branch.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D9607F21FBF9472008AB3C2 /* UIViewController+Branch.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4D9607F51FBF9473008AB3C2 /* UIViewController+Branch.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D9607F31FBF9473008AB3C2 /* UIViewController+Branch.m */; }; - 4DA577181E67B1D600A43BDD /* BNCLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DA577161E67B1D600A43BDD /* BNCLog.m */; }; 4DB327FF1FA10B9000ACF9B0 /* BranchDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DB327FD1FA10B9000ACF9B0 /* BranchDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4DB328001FA10B9000ACF9B0 /* BranchDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DB327FE1FA10B9000ACF9B0 /* BranchDelegate.m */; }; 4DB567341E79F46000A8A324 /* BranchShareLink.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DB567321E79F46000A8A324 /* BranchShareLink.m */; }; @@ -78,7 +76,6 @@ 4DCAC8061F426F7C00405D1D /* BNCEncodingUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 464EA3991ACB38EC000E4094 /* BNCEncodingUtils.h */; }; 4DCAC8091F426F7C00405D1D /* BNCLinkCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E30BCF51A72FE7900AC7402 /* BNCLinkCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4DCAC80A1F426F7C00405D1D /* BNCLinkData.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E30BCF21A71EEEE00AC7402 /* BNCLinkData.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4DCAC80B1F426F7C00405D1D /* BNCLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DA577151E67B1D600A43BDD /* BNCLog.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4DCAC80C1F426F7C00405D1D /* BNCPreferenceHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 670016C11946309100A9E103 /* BNCPreferenceHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4DCAC80E1F426F7C00405D1D /* BNCSystemObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 670016C71946309100A9E103 /* BNCSystemObserver.h */; }; 4DCAC8101F426F7C00405D1D /* Branch.h in Headers */ = {isa = PBXBuildFile; fileRef = 670016BD1946309100A9E103 /* Branch.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -228,7 +225,7 @@ C1614D56285BC8A00098946B /* LinkPresentation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1614D55285BC8A00098946B /* LinkPresentation.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; C1614D5C285BD4AF0098946B /* BranchPluginSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = C1614D5A285BD4AF0098946B /* BranchPluginSupport.h */; }; C1614D5D285BD4AF0098946B /* BranchPluginSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = C1614D5B285BD4AF0098946B /* BranchPluginSupport.m */; }; - C16B975B2B6C21C900FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B975A2B6C21C900FB0631 /* BranchLogger.h */; }; + C16B975B2B6C21C900FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B975A2B6C21C900FB0631 /* BranchLogger.h */; settings = {ATTRIBUTES = (Public, ); }; }; C16B975D2B6C21DC00FB0631 /* BranchLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B975C2B6C21DC00FB0631 /* BranchLogger.m */; }; C16B975F2B716C4700FB0631 /* BranchLoggerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B975E2B716C4700FB0631 /* BranchLoggerTests.m */; }; C17394602A8AEE0E006068F2 /* BNCProductCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = C173945F2A8AEE0E006068F2 /* BNCProductCategory.m */; }; @@ -337,7 +334,6 @@ 4D16838D2098C901008819E3 /* BNCTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCTestCase.m; sourceTree = ""; }; 4D16838E2098C901008819E3 /* BNCEncodingUtilsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCEncodingUtilsTests.m; sourceTree = ""; }; 4D16838F2098C901008819E3 /* BNCSystemObserverTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCSystemObserverTests.m; sourceTree = ""; }; - 4D1683902098C901008819E3 /* BNCLogTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCLogTests.m; sourceTree = ""; }; 4D1683952098C901008819E3 /* BranchEvent.Test.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BranchEvent.Test.swift; sourceTree = ""; }; 4D1683962098C901008819E3 /* BranchUniversalObjectTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchUniversalObjectTests.m; sourceTree = ""; }; 4D1683972098C901008819E3 /* BNCApplicationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCApplicationTests.m; sourceTree = ""; }; @@ -368,8 +364,6 @@ 4D955CCB2035021400FB8008 /* BNCURLFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCURLFilter.m; sourceTree = ""; }; 4D9607F21FBF9472008AB3C2 /* UIViewController+Branch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Branch.h"; sourceTree = ""; }; 4D9607F31FBF9473008AB3C2 /* UIViewController+Branch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Branch.m"; sourceTree = ""; }; - 4DA577151E67B1D600A43BDD /* BNCLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCLog.h; sourceTree = ""; }; - 4DA577161E67B1D600A43BDD /* BNCLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCLog.m; sourceTree = ""; }; 4DA577201E67B28700A43BDD /* NSString+Branch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Branch.h"; sourceTree = ""; }; 4DA577211E67B28700A43BDD /* NSString+Branch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Branch.m"; sourceTree = ""; }; 4DB327FD1FA10B9000ACF9B0 /* BranchDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchDelegate.h; sourceTree = ""; }; @@ -652,7 +646,6 @@ 5F73FC8023314697000EBD32 /* BNCJSONUtilityTests.m */, 5F8BB66D278771890055D2DC /* BNCKeyChainTests.m */, 4D1683842098C901008819E3 /* BNCLinkDataTests.m */, - 4D1683902098C901008819E3 /* BNCLogTests.m */, 5FA9112E29BC662000F3D35C /* BNCNetworkInterfaceTests.m */, 5FDF91582581CDF4009BE5A3 /* BNCPartnerParametersTests.m */, 5FD1786D26DEE49C009696E3 /* BNCPasteboardTests.m */, @@ -866,8 +859,6 @@ 7E30BCF61A72FE7900AC7402 /* BNCLinkCache.m */, 7E30BCF21A71EEEE00AC7402 /* BNCLinkData.h */, 7E30BCF31A71EEEE00AC7402 /* BNCLinkData.m */, - 4DA577151E67B1D600A43BDD /* BNCLog.h */, - 4DA577161E67B1D600A43BDD /* BNCLog.m */, C16B975A2B6C21C900FB0631 /* BranchLogger.h */, C16B975C2B6C21DC00FB0631 /* BranchLogger.m */, 5F92B23D238486E200CA909B /* BNCNetworkInterface.h */, @@ -1006,7 +997,6 @@ 4DCAC80A1F426F7C00405D1D /* BNCLinkData.h in Headers */, 5F73FC7E23313F7A000EBD32 /* BNCJSONUtility.h in Headers */, E729974D28E2BBFA007D91B2 /* BranchPasteControl.h in Headers */, - 4DCAC80B1F426F7C00405D1D /* BNCLog.h in Headers */, 4DCAC80C1F426F7C00405D1D /* BNCPreferenceHelper.h in Headers */, 4DCAC8101F426F7C00405D1D /* Branch.h in Headers */, 4DCAC8111F426F7C00405D1D /* BranchActivityItemProvider.h in Headers */, @@ -1314,7 +1304,6 @@ 5F4101F626851DC7003699AD /* BNCPasteboard.m in Sources */, 4DBC88651F3A55B700E119BF /* NSString+Branch.m in Sources */, 54FF1F8E1BD1D4AE0004CE2E /* BranchUniversalObject.m in Sources */, - 4DA577181E67B1D600A43BDD /* BNCLog.m in Sources */, 5F38021D24DCC2E800E6FAFD /* BranchLATDRequest.m in Sources */, 5F3D6714232C589100454FF1 /* BranchLastAttributedTouchData.m in Sources */, 3A78D576251EB5BF002A25CF /* BranchJsonConfig.m in Sources */, @@ -1424,7 +1413,6 @@ 5FE694382405FA2700E3AEE2 /* BNCCallbackMapTests.m in Sources */, 5FDB04F424E6156800F2F267 /* BNCSKAdNetworkTests.m in Sources */, 5FB6CC13264F0C7C0020E478 /* BNCServerRequestQueueTests.m in Sources */, - 4D1683BA2098C902008819E3 /* BNCLogTests.m in Sources */, 4D1683AE2098C902008819E3 /* BNCLinkDataTests.m in Sources */, 4D7881FF209CF2D4002B750F /* BNCApplication+BNCTest.m in Sources */, C15CC9E02ABCF8C8003CC339 /* BranchActivityItemTests.m in Sources */, diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index 305a295e9..3aeeed7b5 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -12,10 +12,9 @@ #import "ViewController.h" #import "Branch.h" #import "BNCEncodingUtils.h" -#import "BNCLog.h" AppDelegate* appDelegate = nil; -void APPLogHookFunction(NSDate*_Nonnull timestamp, BNCLogLevel level, NSString*_Nullable message); +void APPLogHookFunction(NSDate*_Nonnull timestamp, BranchLogLevel level, NSString*_Nullable message); @implementation AppDelegate @@ -212,7 +211,7 @@ -(void)application:(UIApplication *)application */ // hook Function for SDK - Its for taking control of Logging messages. -void APPLogHookFunction(NSDate*_Nonnull timestamp, BNCLogLevel level, NSString*_Nullable message) { +void APPLogHookFunction(NSDate*_Nonnull timestamp, BranchLogLevel level, NSString*_Nullable message) { [appDelegate processLogMessage:message]; } diff --git a/Branch-TestBed/Branch-TestBed/Branch-TestBed-Info.plist b/Branch-TestBed/Branch-TestBed/Branch-TestBed-Info.plist index ee2bcc7d9..e7f466f5c 100644 --- a/Branch-TestBed/Branch-TestBed/Branch-TestBed-Info.plist +++ b/Branch-TestBed/Branch-TestBed/Branch-TestBed-Info.plist @@ -4,8 +4,6 @@ AppIdentifierPrefix $(AppIdentifierPrefix) - BranchLogLevel - BNCLogLevelAll CFBundleDevelopmentRegion en CFBundleDisplayName diff --git a/BranchSDK/BNCAppGroupsData.m b/BranchSDK/BNCAppGroupsData.m index e7885d9d9..8ce782b95 100644 --- a/BranchSDK/BNCAppGroupsData.m +++ b/BranchSDK/BNCAppGroupsData.m @@ -7,8 +7,6 @@ // #import "BNCAppGroupsData.h" - -#import "BNCLog.h" #import "BNCApplication.h" #import "BNCPreferenceHelper.h" #import "BNCSystemObserver.h" diff --git a/BranchSDK/BNCApplication.m b/BranchSDK/BNCApplication.m index f5e0b8996..2bbecb03a 100644 --- a/BranchSDK/BNCApplication.m +++ b/BranchSDK/BNCApplication.m @@ -9,7 +9,7 @@ */ #import "BNCApplication.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "BNCKeyChain.h" static NSString*const kBranchKeychainService = @"BranchKeychainService"; @@ -87,12 +87,12 @@ + (NSDate*) currentBuildDate { NSFileManager *fileManager = [NSFileManager defaultManager]; NSDictionary *attributes = [fileManager attributesOfItemAtPath:appURL.path error:&error]; if (error) { - BNCLogError([NSString stringWithFormat:@"Can't get build date: %@.", error]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Can't get build date: %@.", error] error:error]; return nil; } NSDate * buildDate = [attributes fileCreationDate]; if (buildDate == nil || [buildDate timeIntervalSince1970] <= 0.0) { - BNCLogError([NSString stringWithFormat:@"Invalid build date: %@.", buildDate]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Invalid build date: %@.", buildDate] error:nil]; } return buildDate; } @@ -111,7 +111,8 @@ + (NSDate*) firstInstallBuildDate { forService:kBranchKeychainService key:kBranchKeychainFirstBuildKey cloudAccessGroup:nil]; - if (error) BNCLogError([NSString stringWithFormat:@"Keychain store: %@.", error]); + if (error) [[BranchLogger shared] logError:[NSString stringWithFormat:@"Keychain store: %@.", error] error:error]; + return firstBuildDate; } @@ -124,7 +125,7 @@ + (NSDate *) currentInstallDate { #endif if (installDate == nil || [installDate timeIntervalSince1970] <= 0.0) { - BNCLogWarning([NSString stringWithFormat:@"Invalid install date, using [NSDate date]."]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Invalid install date, using [NSDate date]."]]; } return installDate; } @@ -135,7 +136,7 @@ + (NSDate *)creationDateForLibraryDirectory { NSURL *directoryURL = [[fileManager URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] firstObject]; NSDictionary *attributes = [fileManager attributesOfItemAtPath:directoryURL.path error:&error]; if (error) { - BNCLogError([NSString stringWithFormat:@"Can't get creation date for Library directory: %@", error]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Can't get creation date for Library directory: %@", error] error:error]; return nil; } return [attributes fileCreationDate]; @@ -155,7 +156,7 @@ + (NSDate*) firstInstallDate { // save filesystem time to keychain error = [BNCKeyChain storeDate:firstInstallDate forService:kBranchKeychainService key:kBranchKeychainFirstInstalldKey cloudAccessGroup:nil]; if (error) { - BNCLogError([NSString stringWithFormat:@"Keychain store: %@.", error]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Keychain store: %@.", error] error:error]; } return firstInstallDate; } diff --git a/BranchSDK/BNCDeviceInfo.m b/BranchSDK/BNCDeviceInfo.m index abd311e3a..fd6b8c295 100644 --- a/BranchSDK/BNCDeviceInfo.m +++ b/BranchSDK/BNCDeviceInfo.m @@ -9,7 +9,6 @@ #import "BNCDeviceInfo.h" #import "BNCPreferenceHelper.h" #import "BNCSystemObserver.h" -#import "BNCLog.h" #import "BNCConfig.h" #import "BNCNetworkInterface.h" #import "BNCReachability.h" diff --git a/BranchSDK/BNCEncodingUtils.m b/BranchSDK/BNCEncodingUtils.m index 8d53e3750..57cf9e16c 100644 --- a/BranchSDK/BNCEncodingUtils.m +++ b/BranchSDK/BNCEncodingUtils.m @@ -8,8 +8,8 @@ #import "BNCEncodingUtils.h" #import "BNCPreferenceHelper.h" -#import "BNCLog.h" #import +#import "BranchLogger.h" #pragma mark BNCWireFormat @@ -167,7 +167,7 @@ + (NSString *)encodeDictionaryToJsonString:(NSDictionary *)dictionary { // protect against non-string keys if (![key isKindOfClass:[NSString class]]) { - BNCLogError([NSString stringWithFormat:@"Unexpected key type %@. Skipping key.", [key class]]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Unexpected key type %@. Skipping key.", [key class]] error:nil]; continue; } @@ -208,7 +208,7 @@ + (NSString *)encodeDictionaryToJsonString:(NSDictionary *)dictionary { } else { // If this type is not a known type, don't attempt to encode it. - BNCLogError([NSString stringWithFormat:@"Cannot encode value for key %@. The value is not an accepted type.", key]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Cannot encode value for key %@. The value is not an accepted type.", key] error:nil]; continue; } @@ -230,7 +230,7 @@ + (NSString *)encodeDictionaryToJsonString:(NSDictionary *)dictionary { [encodedDictionary appendString:@"}"]; - BNCLogDebugSDK([NSString stringWithFormat:@"Encoded dictionary: %@.", encodedDictionary]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Encoded dictionary: %@.", encodedDictionary]]; return encodedDictionary; } @@ -272,7 +272,7 @@ + (NSString *)encodeArrayToJsonString:(NSArray *)array { } else { // If this type is not a known type, don't attempt to encode it. - BNCLogError([NSString stringWithFormat:@"Cannot encode value %@. The value is not an accepted type.", obj]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Cannot encode value %@. The value is not an accepted type.", obj] error:nil]; continue; } @@ -290,7 +290,8 @@ + (NSString *)encodeArrayToJsonString:(NSArray *)array { [encodedArray deleteCharactersInRange:NSMakeRange([encodedArray length] - 1, 1)]; [encodedArray appendString:@"]"]; - BNCLogDebugSDK([NSString stringWithFormat:@"Encoded array: %@.", encodedArray]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Encoded array: %@.", encodedArray]]; + return encodedArray; } @@ -323,7 +324,7 @@ + (NSString *)encodeDictionaryToQueryString:(NSDictionary *)dictionary { } else { // If this type is not a known type, don't attempt to encode it. - BNCLogError([NSString stringWithFormat:@"Cannot encode value %@. The value is not an accepted type.", obj]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Cannot encode value %@. The value is not an accepted type.", obj] error:nil]; continue; } diff --git a/BranchSDK/BNCKeyChain.m b/BranchSDK/BNCKeyChain.m index 6edd76ac9..c2e1da340 100644 --- a/BranchSDK/BNCKeyChain.m +++ b/BranchSDK/BNCKeyChain.m @@ -9,7 +9,7 @@ */ #import "BNCKeyChain.h" -#import "BNCLog.h" +#import "BranchLogger.h" // Apple Keychain Reference: // https://developer.apple.com/library/content/documentation/Conceptual/ @@ -57,7 +57,7 @@ + (NSDate *) retrieveDateForService:(NSString *)service key:(NSString *)key erro OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dictionary, (CFTypeRef *)&valueData); if (status != errSecSuccess) { NSError *localError = [self errorWithKey:key OSStatus:status]; - BNCLogDebugSDK([NSString stringWithFormat:@"Can't retrieve key: %@.", localError]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Can't retrieve key: %@.", localError]]; if (error) *error = localError; if (valueData) CFRelease(valueData); return nil; @@ -106,7 +106,7 @@ + (NSError *) storeDate:(NSDate *)date OSStatus status = SecItemDelete((__bridge CFDictionaryRef)dictionary); if (status != errSecSuccess && status != errSecItemNotFound) { NSError *error = [self errorWithKey:key OSStatus:status]; - BNCLogDebugSDK([NSString stringWithFormat:@"Can't clear to store key: %@.", error]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Can't clear to store key: %@.", error]]; } dictionary[(__bridge id)kSecValueData] = valueData; @@ -122,7 +122,7 @@ + (NSError *) storeDate:(NSDate *)date status = SecItemAdd((__bridge CFDictionaryRef)dictionary, NULL); if (status) { NSError *error = [self errorWithKey:key OSStatus:status]; - BNCLogDebugSDK([NSString stringWithFormat:@"Can't store key: %@.", error]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Can't store key: %@.", error]]; return error; } return nil; @@ -140,7 +140,7 @@ + (NSError*) removeValuesForService:(NSString *)service key:(NSString *)key { if (status == errSecItemNotFound) status = errSecSuccess; if (status) { NSError *error = [self errorWithKey:key OSStatus:status]; - BNCLogDebugSDK([NSString stringWithFormat:@"Can't remove key: %@.", error]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Can't remove key: %@.", error]]; return error; } return nil; @@ -154,8 +154,8 @@ + (NSString * _Nullable) securityAccessGroup { // First store a value: NSError *error = [self storeDate:[NSDate date] forService:@"BranchKeychainService" key:@"Temp" cloudAccessGroup:nil]; - if (error) BNCLogDebugSDK([NSString stringWithFormat:@"Error storing temp value: %@.", error]); - + if (error) [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Error storing temp value: %@.", error]]; + NSDictionary* dictionary = @{ (__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword, (__bridge id)kSecAttrService: @"BranchKeychainService", @@ -167,8 +167,8 @@ + (NSString * _Nullable) securityAccessGroup { OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dictionary, (CFTypeRef*)&resultDictionary); if (status == errSecItemNotFound) return nil; if (status != errSecSuccess) { - BNCLogDebugSDK([NSString stringWithFormat:@"Get securityAccessGroup returned(%ld): %@.", - (long) status, [self errorWithKey:nil OSStatus:status]]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Get securityAccessGroup returned(%ld): %@.", + (long) status, [self errorWithKey:nil OSStatus:status]]]; return nil; } NSString*group = diff --git a/BranchSDK/BNCLog.h b/BranchSDK/BNCLog.h deleted file mode 100644 index 4b20b5150..000000000 --- a/BranchSDK/BNCLog.h +++ /dev/null @@ -1,88 +0,0 @@ -/** - @file BNCLog.h - @package Branch-SDK - @brief Simple logging functions. - - @author Edward Smith - @date October 2016 - @copyright Copyright © 2016 Branch. All rights reserved. -*/ - -///@functiongroup Branch Logging Functions -#import - -#pragma mark Log Message Severity - -/// Log message severity -typedef NS_ENUM(NSInteger, BNCLogLevel) { - BNCLogLevelAll = 0, - BNCLogLevelDebugSDK = BNCLogLevelAll, - BNCLogLevelBreakPoint, - BNCLogLevelDebug, - BNCLogLevelWarning, - BNCLogLevelError, - BNCLogLevelAssert, - BNCLogLevelLog, - BNCLogLevelNone, - BNCLogLevelMax -}; - -/*! -* @return Returns the current log severity display level. -*/ -extern BNCLogLevel BNCLogDisplayLevel(void); - -/*! -* @param level Sets the current display level for log messages. -*/ -extern void BNCLogSetDisplayLevel(BNCLogLevel level); - -/*! -* @param level The log level to convert to a string. -* @return Returns the string indicating the log level. -*/ -extern NSString *_Nonnull BNCLogStringFromLogLevel(BNCLogLevel level); - -/*! -* @param string A string indicating the log level. -* @return Returns The log level corresponding to the string. -*/ -extern BNCLogLevel BNCLogLevelFromString(NSString*_Null_unspecified string); - -///@name Pre-defined log message handlers -- -typedef void (*BNCLogOutputFunctionPtr)(NSDate*_Nonnull timestamp, BNCLogLevel level, NSString*_Nullable message); - -///@param functionPtr A pointer to the logging function. Setting the parameter to NULL will flush -/// and close the currently set log function and future log messages will be -/// ignored until a non-NULL logging function is set. -extern void BNCLogSetOutputFunction(BNCLogOutputFunctionPtr _Nullable functionPtr); - -#pragma mark - BNCLogWriteMessage - -/// The main logging function used in the variadic logging defines. -extern void BNCLogWriteMessage( - BNCLogLevel logLevel, - const char *_Nullable sourceFileName, - int32_t sourceLineNumber, - NSString *_Nullable message -); - -///@param format Log an info message -#define BNCLogDebugSDK(...) \ - do { BNCLogWriteMessage(BNCLogLevelDebugSDK, __FILE__, __LINE__, __VA_ARGS__); } while (0) - -///@param format Log a debug message -#define BNCLogDebug(...) \ - do { BNCLogWriteMessage(BNCLogLevelDebug, __FILE__, __LINE__, __VA_ARGS__); } while (0) - -///@param format Log a warning message -#define BNCLogWarning(...) \ - do { BNCLogWriteMessage(BNCLogLevelWarning, __FILE__, __LINE__, __VA_ARGS__); } while (0) - -///@param format Log an error message -#define BNCLogError(...) \ - do { BNCLogWriteMessage(BNCLogLevelError, __FILE__, __LINE__, __VA_ARGS__); } while (0) - -///@param format Log a message -#define BNCLog(...) \ - do { BNCLogWriteMessage(BNCLogLevelLog, __FILE__, __LINE__, __VA_ARGS__); } while (0) diff --git a/BranchSDK/BNCLog.m b/BranchSDK/BNCLog.m deleted file mode 100644 index 110523860..000000000 --- a/BranchSDK/BNCLog.m +++ /dev/null @@ -1,109 +0,0 @@ -/** - @file BNCLog.m - @package Branch-SDK - @brief Simple logging functions. - - @author Edward Smith - @date October 2016 - @copyright Copyright © 2016 Branch. All rights reserved. -*/ - -#import "BNCLog.h" - -#define _countof(array) (sizeof(array)/sizeof(array[0])) - -static BNCLogOutputFunctionPtr bnc_LoggingFunction = nil; // Default to just NSLog output. - -// A fallback attempt at logging if an error occurs in BNCLog. -// BNCLog can't log itself, but if an error occurs it uses this simple define: -extern void BNCLogInternalError(NSString *message); -void BNCLogInternalError(NSString *message) { - NSLog(@"[branch.io] BNCLog.m (%d) Log error: %@", __LINE__, message); -} - -#pragma mark - Log Message Severity - -static BNCLogLevel bnc_LogDisplayLevel = BNCLogLevelWarning; - -BNCLogLevel BNCLogDisplayLevel(void) { - BNCLogLevel level = bnc_LogDisplayLevel; - return level; -} - -void BNCLogSetDisplayLevel(BNCLogLevel level) { - bnc_LogDisplayLevel = level; -} - -static NSString*const bnc_logLevelStrings[] = { - @"BNCLogLevelAll", - @"BNCLogLevelBreakPoint", - @"BNCLogLevelDebug", - @"BNCLogLevelWarning", - @"BNCLogLevelError", - @"BNCLogLevelAssert", - @"BNCLogLevelLog", - @"BNCLogLevelNone", - @"BNCLogLevelMax" -}; - -NSString* BNCLogStringFromLogLevel(BNCLogLevel level) { - level = MAX(MIN(level, BNCLogLevelMax), 0); - return bnc_logLevelStrings[level]; -} - -BNCLogLevel BNCLogLevelFromString(NSString*string) { - if (!string) return BNCLogLevelNone; - for (NSUInteger i = 0; i < _countof(bnc_logLevelStrings); ++i) { - if ([bnc_logLevelStrings[i] isEqualToString:string]) { - return i; - } - } - if ([string isEqualToString:@"BNCLogLevelDebugSDK"]) { - return BNCLogLevelDebugSDK; - } - return BNCLogLevelNone; -} - -void BNCLogSetOutputFunction(BNCLogOutputFunctionPtr _Nullable logFunction) { - bnc_LoggingFunction = logFunction; -} -#pragma mark - BNCLogInternal - -void BNCLogWriteMessage( - BNCLogLevel logLevel, - const char *_Nullable file, - int32_t lineNumber, - NSString *_Nullable message - ) { - if (!file) file = ""; - if (!message) message = @""; - if (![message isKindOfClass:[NSString class]]) { - message = [NSString stringWithFormat:@"0x%016llx <%@> %@", - (uint64_t) message, message.class, message.description]; - } - - NSString* filename = - [[NSString stringWithCString:file encoding:NSMacOSRomanStringEncoding] - lastPathComponent]; - - NSString * const logLevels[BNCLogLevelMax] = { - @"DebugSDK", - @"Break", - @"Debug", - @"Warning", - @"Error", - @"Assert", - @"Log", - @"None", - }; - - logLevel = MAX(MIN(logLevel, BNCLogLevelMax-1), 0); - NSString *levelString = logLevels[logLevel]; - NSString *s = [NSString stringWithFormat:@"[branch.io] %@(%d) %@: %@", filename, lineNumber, levelString, message]; - - if (logLevel >= bnc_LogDisplayLevel) { - NSLog(@"%@", s); // Upgrade this to unified logging when we can. - if (bnc_LoggingFunction) - bnc_LoggingFunction([NSDate date], logLevel, message); - } -} diff --git a/BranchSDK/BNCNetworkInterface.m b/BranchSDK/BNCNetworkInterface.m index 7f384660c..87dffc8b2 100644 --- a/BranchSDK/BNCNetworkInterface.m +++ b/BranchSDK/BNCNetworkInterface.m @@ -7,7 +7,7 @@ // #import "BNCNetworkInterface.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import #import @@ -49,16 +49,14 @@ - (NSString*) description { // Retrieve the current interfaces - returns 0 on success if (getifaddrs(&interfaces) != 0) { int e = errno; - BNCLogError([NSString stringWithFormat:@"Can't read ip address: (%d): %s.", e, strerror(e)]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Can't read ip address: (%d): %s.", e, strerror(e)] error:nil]; goto exit; } // Loop through linked list of interfaces -- struct ifaddrs *interface = NULL; for (interface=interfaces; interface; interface=interface->ifa_next) { - - // BNCLogDebugSDK(@"Found %s: %x.", interface->ifa_name, interface->ifa_flags); - + // Check the state: IFF_RUNNING, IFF_UP, IFF_LOOPBACK, etc. if ((interface->ifa_flags & IFF_UP) && (interface->ifa_flags & IFF_RUNNING) && !(interface->ifa_flags & IFF_LOOPBACK)) { } else { diff --git a/BranchSDK/BNCNetworkService.m b/BranchSDK/BNCNetworkService.m index 255350470..ea3ee4d16 100644 --- a/BranchSDK/BNCNetworkService.m +++ b/BranchSDK/BNCNetworkService.m @@ -8,7 +8,7 @@ #import "BNCNetworkService.h" #import "BNCEncodingUtils.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "NSError+Branch.h" #import "BranchLogger.h" @@ -153,7 +153,7 @@ - (BNCNetworkOperation*) networkOperationWithURLRequest:(NSMutableURLRequest*)re BNCNetworkOperation *operation = [BNCNetworkOperation new]; if (![request isKindOfClass:[NSMutableURLRequest class]]) { - BNCLogError(@"A `NSMutableURLRequest` request parameter was expected."); + [[BranchLogger shared] logError:@"A `NSMutableURLRequest` request parameter was expected." error:nil]; return nil; } operation.request = request; @@ -167,45 +167,42 @@ - (void) startOperation:(BNCNetworkOperation*)operation { if (!operation.startDate) { operation.startDate = [NSDate date]; } + if (!operation.timeoutDate) { NSTimeInterval timeoutInterval = operation.request.timeoutInterval; if (timeoutInterval < 0.0) timeoutInterval = self.defaultTimeoutInterval; operation.timeoutDate = - [[operation startDate] dateByAddingTimeInterval:timeoutInterval]; + [[operation startDate] dateByAddingTimeInterval:timeoutInterval]; } + if ([operation.request isKindOfClass:[NSMutableURLRequest class]]) { ((NSMutableURLRequest*)operation.request).timeoutInterval = - [operation.timeoutDate timeIntervalSinceDate:[NSDate date]]; + [operation.timeoutDate timeIntervalSinceDate:[NSDate date]]; } else { - BNCLogError(@"SDK logic error. Expected mutable request in `start` method."); + [[BranchLogger shared] logError:@"SDK logic error. Expected mutable request in `start` method." error:nil]; } + operation.sessionTask = - [self.session dataTaskWithRequest:operation.request - completionHandler: - ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { - operation.responseData = data; - operation.response = (NSHTTPURLResponse*) response; - operation.error = error; - if (operation.response.statusCode == 404) { - /* Don't print 404 messages because they look like an error. - BNCLogDebugSDK(@"Network finish operation %@ %1.3fs. Status %ld.", - operation.request.URL.absoluteString, - [[NSDate date] timeIntervalSinceDate:operation.startDate], - (long)operation.response.statusCode); - */ - } else { - BNCLogDebug([NSString stringWithFormat:@"Network finish operation %@ %1.3fs. Status %ld error %@.\n%@.", - operation.request.URL.absoluteString, - [[NSDate date] timeIntervalSinceDate:operation.startDate], - (long)operation.response.statusCode, - operation.error, - operation.stringFromResponseData]); - } - if (operation.completionBlock) - operation.completionBlock(operation); - }]; - + [self.session dataTaskWithRequest:operation.request + completionHandler: + ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + operation.responseData = data; + operation.response = (NSHTTPURLResponse*) response; + operation.error = error; + + if (operation.response.statusCode != 404) { + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Network finish operation %@ %1.3fs. Status %ld error %@.\n%@.", + operation.request.URL.absoluteString, + [[NSDate date] timeIntervalSinceDate:operation.startDate], + (long)operation.response.statusCode, + operation.error, + operation.stringFromResponseData]]; + } + if (operation.completionBlock) + operation.completionBlock(operation); + }]; + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Network start operation %@.", operation.request.URL]]; [operation.sessionTask resume]; diff --git a/BranchSDK/BNCPartnerParameters.m b/BranchSDK/BNCPartnerParameters.m index 8981aba3e..828edc1dc 100644 --- a/BranchSDK/BNCPartnerParameters.m +++ b/BranchSDK/BNCPartnerParameters.m @@ -7,7 +7,7 @@ // #import "BNCPartnerParameters.h" -#import "BNCLog.h" +#import "BranchLogger.h" @interface BNCPartnerParameters() @property (nonatomic, strong, readwrite) NSMutableDictionary *> *parameters; @@ -54,7 +54,7 @@ - (void)addFacebookParameterWithName:(NSString *)name value:(NSString *)value { if ([self sha256HashSanityCheckValue:value]) { [self addParameterWithName:name value:value partnerName:@"fb"]; } else { - BNCLogWarning(@"Partner parameter does not appear to be SHA256 hashed. Dropping the parameter."); + [[BranchLogger shared] logWarning:@"Partner parameter does not appear to be SHA256 hashed. Dropping the parameter."]; } } @@ -62,7 +62,7 @@ - (void)addSnapParameterWithName:(NSString *)name value:(NSString *)value { if ([self sha256HashSanityCheckValue:value]) { [self addParameterWithName:name value:value partnerName:@"snap"]; } else { - BNCLogWarning(@"Partner parameter does not appear to be SHA256 hashed. Dropping the parameter."); + [[BranchLogger shared] logWarning:@"Partner parameter does not appear to be SHA256 hashed. Dropping the parameter."]; } } diff --git a/BranchSDK/BNCPreferenceHelper.m b/BranchSDK/BNCPreferenceHelper.m index fb7a3ca58..d5cabb90f 100644 --- a/BranchSDK/BNCPreferenceHelper.m +++ b/BranchSDK/BNCPreferenceHelper.m @@ -10,7 +10,7 @@ #import "BNCEncodingUtils.h" #import "BNCConfig.h" #import "Branch.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "BranchConstants.h" #import "NSString+Branch.h" #import "BNCSKAdNetwork.h" @@ -163,7 +163,7 @@ - (void)setBranchAPIURL:(NSString *)url { [self writeObjectToDefaults:BRANCH_PREFS_KEY_API_URL value:_branchAPIURL]; } } else { - BNCLogWarning(@"Ignoring invalid custom API URL"); + [[BranchLogger shared] logWarning:@"Ignoring invalid custom API URL"]; } } @@ -191,7 +191,7 @@ - (void)setPatternListURL:(NSString *)url { [self writeObjectToDefaults:BRANCH_PREFS_KEY_PATTERN_LIST_URL value:url]; } } else { - BNCLogWarning(@"Ignoring invalid custom CDN URL"); + [[BranchLogger shared] logWarning:@"Ignoring invalid custom CDN URL"]; } } @@ -892,7 +892,7 @@ - (void)persistPrefsToDisk { NSError *error = nil; [data writeToURL:prefsURL options:NSDataWritingAtomic error:&error]; if (error) { - BNCLogWarning([NSString stringWithFormat:@"Failed to persist preferences: %@.", error]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Failed to persist preferences: %@.", error]]; } }]; [_persistPrefsQueue addOperation:newPersistOp]; @@ -907,7 +907,7 @@ - (NSData *)serializePrefDict:(NSMutableDictionary *)dict { @try { data = [NSKeyedArchiver archivedDataWithRootObject:dict requiringSecureCoding:YES error:NULL]; } @catch (id exception) { - BNCLogWarning([NSString stringWithFormat:@"Exception serializing preferences dict: %@.", exception]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Exception serializing preferences dict: %@.", exception]]; } return data; } @@ -938,10 +938,10 @@ - (NSData *)loadPrefData { NSError *error = nil; data = [NSData dataWithContentsOfURL:self.class.URLForPrefsFile options:0 error:&error]; if (error || !data) { - BNCLogWarning(@"Failed to load preferences from storage."); + [[BranchLogger shared] logWarning:@"Failed to load preferences from storage."]; } } @catch (NSException *) { - BNCLogWarning(@"Failed to load preferences from storage."); + [[BranchLogger shared] logWarning:@"Failed to load preferences from storage."]; } return data; } @@ -954,7 +954,7 @@ - (NSMutableDictionary *)deserializePrefDictFromData:(NSData *)data { dict = [NSKeyedUnarchiver unarchivedObjectOfClasses:classes fromData:data error:&error]; if (error) { - BNCLogWarning(@"Failed to load preferences from storage."); + [[BranchLogger shared] logWarning:@"Failed to load preferences from storage."]; } } @@ -1054,8 +1054,7 @@ + (NSURL* _Nonnull) URLForPrefsFile { if (success) { return branchURL; } else { - // BNCLog is dependent on BNCCreateDirectoryForBranchURLWithSearchPath_Unthreaded and cannot be used to log errors from it. - NSLog(@"CreateBranchURL failed: %@ URL: %@.", error, branchURL); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"CreateBranchURL failed: %@ URL: %@.", error, branchURL] error:error]; } } return nil; @@ -1094,8 +1093,7 @@ + (NSURL* _Nonnull) URLForPrefsFile { attributes:nil error:&error]; if (!success) { - // BNCLog is dependent on BNCURLForBranchDirectory_Unthreaded and cannot be used to log errors from it. - NSLog(@"Worst case CreateBranchURL error was: %@ URL: %@.", error, branchURL); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Worst case CreateBranchURL error was: %@ URL: %@.", error, branchURL] error:error]; } return branchURL; } diff --git a/BranchSDK/BNCReferringURLUtility.m b/BranchSDK/BNCReferringURLUtility.m index f026b7379..c4a9c965a 100644 --- a/BranchSDK/BNCReferringURLUtility.m +++ b/BranchSDK/BNCReferringURLUtility.m @@ -10,7 +10,7 @@ #import "BNCPreferenceHelper.h" #import "BranchConstants.h" #import "BNCUrlQueryParameter.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import @interface BNCReferringURLUtility() @@ -286,7 +286,7 @@ - (void)checkForAndMigrateOldGbraid { self.preferenceHelper.referrerGBRAIDValidityWindow = 0; self.preferenceHelper.referrerGBRAIDInitDate = nil; - BNCLogDebug(@"Updated old Gbraid to new BNCUrlQueryParameter"); + [[BranchLogger shared] logDebug:@"Updated old Gbraid to new BNCUrlQueryParameter"]; } } diff --git a/BranchSDK/BNCSKAdNetwork.m b/BranchSDK/BNCSKAdNetwork.m index f29a1ccec..71ff70b93 100644 --- a/BranchSDK/BNCSKAdNetwork.m +++ b/BranchSDK/BNCSKAdNetwork.m @@ -10,7 +10,7 @@ #import "BNCApplication.h" #import "BNCPreferenceHelper.h" #import "BranchConstants.h" -#import "BNCLog.h" +#import "BranchLogger.h" @interface BNCSKAdNetwork() @@ -73,8 +73,7 @@ - (BOOL)shouldAttemptSKAdNetworkCallout { - (void)registerAppForAdNetworkAttribution { if (@available(iOS 14.0, macCatalyst 14.0, *)) { if ([self shouldAttemptSKAdNetworkCallout] && [self.skAdNetworkClass respondsToSelector:self.skAdNetworkRegisterAppForAdNetworkAttribution]) { - BNCLogDebug(@"Calling registerAppForAdNetworkAttribution"); - + [[BranchLogger shared] logDebug:@"Calling registerAppForAdNetworkAttribution"]; // Equivalent call [SKAdNetwork registerAppForAdNetworkAttribution]; ((id (*)(id, SEL))[self.skAdNetworkClass methodForSelector:self.skAdNetworkRegisterAppForAdNetworkAttribution])(self.skAdNetworkClass, self.skAdNetworkRegisterAppForAdNetworkAttribution); } @@ -84,8 +83,8 @@ - (void)registerAppForAdNetworkAttribution { - (void)updateConversionValue:(NSInteger)conversionValue { if (@available(iOS 14.0, macCatalyst 14.0, *)) { if ([self shouldAttemptSKAdNetworkCallout] && [self.skAdNetworkClass respondsToSelector:self.skAdNetworkUpdateConversionValue]) { - BNCLogDebug([NSString stringWithFormat:@"Calling updateConversionValue:%ld", (long)conversionValue]); - + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Calling updateConversionValue:%ld", (long)conversionValue]]; + // Equivalent call [SKAdNetwork updateConversionValue:conversionValue]; ((id (*)(id, SEL, NSInteger))[self.skAdNetworkClass methodForSelector:self.skAdNetworkUpdateConversionValue])(self.skAdNetworkClass, self.skAdNetworkUpdateConversionValue, conversionValue); } @@ -95,7 +94,7 @@ - (void)updateConversionValue:(NSInteger)conversionValue { - (void)updatePostbackConversionValue:(NSInteger)conversionValue completionHandler:(void (^)(NSError *error))completion { if (@available(iOS 15.4, macCatalyst 15.4, *)) { if ([self shouldAttemptSKAdNetworkCallout] && [self.skAdNetworkClass respondsToSelector:self.skAdNetworkUpdatePostbackConversionValue]) { - BNCLogDebug([NSString stringWithFormat:@"Calling updatePostbackConversionValue:%ld completionHandler:completion", (long)conversionValue]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Calling updatePostbackConversionValue:%ld completionHandler:completion", (long)conversionValue]]; // Equivalent call [SKAdNetwork updatePostbackConversionValue:completionHandler:]; ((id (*)(id, SEL, NSInteger,void (^)(NSError *error)))[self.skAdNetworkClass methodForSelector:self.skAdNetworkUpdatePostbackConversionValue])(self.skAdNetworkClass, self.skAdNetworkUpdatePostbackConversionValue, conversionValue, completion); @@ -110,8 +109,7 @@ - (void)updatePostbackConversionValue:(NSInteger)fineValue completionHandler:(void (^)(NSError *error))completion { if (@available(iOS 16.1, macCatalyst 16.1, *)) { if ([self shouldAttemptSKAdNetworkCallout] && [self.skAdNetworkClass respondsToSelector:self.skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow]) { - BNCLogDebug([NSString stringWithFormat:@"Calling updatePostbackConversionValue:%ld coarseValue:%@ lockWindow:%d completionHandler:completion", (long)fineValue, coarseValue, lockWindow]); - + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Calling updatePostbackConversionValue:%ld coarseValue:%@ lockWindow:%d completionHandler:completion", (long)fineValue, coarseValue, lockWindow]]; // Equivalent call [SKAdNetwork updatePostbackConversionValue:coarseValue:lockWindow:completionHandler:]; ((id (*)(id, SEL, NSInteger, NSString *, BOOL, void (^)(NSError *error)))[self.skAdNetworkClass methodForSelector:self.skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow])(self.skAdNetworkClass, self.skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow, fineValue, coarseValue, lockWindow, completion); } diff --git a/BranchSDK/BNCServerInterface.m b/BranchSDK/BNCServerInterface.m index eaa95e182..030a993bf 100644 --- a/BranchSDK/BNCServerInterface.m +++ b/BranchSDK/BNCServerInterface.m @@ -12,7 +12,7 @@ #import "NSError+Branch.h" #import "BranchConstants.h" #import "NSMutableDictionary+Branch.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "Branch.h" #import "BNCSKAdNetwork.h" #import "BNCReferringURLUtility.h" @@ -118,7 +118,7 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN dispatch_time(DISPATCH_TIME_NOW, self.preferenceHelper.retryInterval * NSEC_PER_SEC); dispatch_after(dispatchTime, dispatch_get_main_queue(), ^{ if (retryHandler) { - BNCLogDebug([NSString stringWithFormat:@"Retrying request with url %@", request.URL.relativePath]); + [[BranchLogger shared] logDebug: [NSString stringWithFormat:@"Retrying request with url %@", request.URL.relativePath]]; // Create the next request NSURLRequest *retryRequest = retryHandler(retryNumber); [self genericHTTPRequest:retryRequest @@ -155,8 +155,7 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN } if (branchError) { - BNCLogError([NSString stringWithFormat:@"An error prevented request to %@ from completing: %@", - request.URL.absoluteString, branchError]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"An error prevented request to %@ from completing: %@", request.URL.absoluteString, branchError] error:branchError]; } // Don't call on the main queue since it might be blocked. @@ -171,7 +170,7 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN if (![self isLinkingRelatedRequest:endpoint]) { [[BNCPreferenceHelper sharedInstance] clearTrackingInformation]; NSError *error = [NSError branchErrorWithCode:BNCTrackingDisabledError]; - BNCLogWarning([NSString stringWithFormat:@"Dropping Request %@: - %@", endpoint, error]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Dropping Request %@: - %@", endpoint, error]]; if (callback) { callback(nil, error); } @@ -184,7 +183,7 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN [operation start]; NSError *error = [self verifyNetworkOperation:operation]; if (error) { - BNCLogError([NSString stringWithFormat:@"Network service error: %@.", error]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Network service error: %@.", error] error:error]; if (callback) { callback(nil, error); } @@ -279,8 +278,7 @@ - (NSURLRequest *)prepareGetRequest:(NSDictionary *)params url:(NSString *)url k NSDictionary *tmp = [self addRetryCount:retryNumber toJSON:params]; NSString *requestUrlString = [NSString stringWithFormat:@"%@%@", url, [BNCEncodingUtils encodeDictionaryToQueryString:tmp]]; - BNCLogDebug([NSString stringWithFormat:@"URL: %@", requestUrlString]); - + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"URL: %@", requestUrlString]]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestUrlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:self.preferenceHelper.timeout]; @@ -297,11 +295,10 @@ - (NSURLRequest *)preparePostRequest:(NSDictionary *)params url:(NSString *)url NSData *postData = [BNCEncodingUtils encodeDictionaryToJsonData:tmp]; NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]]; - BNCLogDebug([NSString stringWithFormat:@"URL: %@.\n", url]); - BNCLogDebug([NSString stringWithFormat:@"Body: %@\nJSON: %@.", - params, - [[NSString alloc] initWithData:postData encoding:NSUTF8StringEncoding]] - ); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"URL: %@.\n", url]]; + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Body: %@\nJSON: %@.", + params, + [[NSString alloc] initWithData:postData encoding:NSUTF8StringEncoding]]]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] diff --git a/BranchSDK/BNCServerRequest.m b/BranchSDK/BNCServerRequest.m index ede44b0d8..decdf92db 100644 --- a/BranchSDK/BNCServerRequest.m +++ b/BranchSDK/BNCServerRequest.m @@ -7,16 +7,16 @@ // #import "BNCServerRequest.h" -#import "BNCLog.h" +#import "BranchLogger.h" @implementation BNCServerRequest - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback { - BNCLogError(@"BNCServerRequest subclasses must implement makeRequest:key:callback:."); + [[BranchLogger shared] logError:@"BNCServerRequest subclasses must implement makeRequest:key:callback:." error:nil]; } - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { - BNCLogError(@"BNCServerRequest subclasses must implement processResponse:error:."); + [[BranchLogger shared] logError:@"BNCServerRequest subclasses must implement processResponse:error:." error:nil]; } - (id)initWithCoder:(NSCoder *)aDecoder { diff --git a/BranchSDK/BNCServerRequestQueue.m b/BranchSDK/BNCServerRequestQueue.m index dea5a88f7..60b528e67 100755 --- a/BranchSDK/BNCServerRequestQueue.m +++ b/BranchSDK/BNCServerRequestQueue.m @@ -15,7 +15,7 @@ #import "BranchOpenRequest.h" #import "BranchEvent.h" -#import "BNCLog.h" +#import "BranchLogger.h" static NSString * const BRANCH_QUEUE_FILE = @"BNCServerRequestQueue"; @@ -68,7 +68,7 @@ - (void)enqueue:(BNCServerRequest *)request { - (void)insert:(BNCServerRequest *)request at:(NSUInteger)index { @synchronized (self) { if (index > self.queue.count) { - BNCLogError(@"Invalid queue operation: index out of bound!"); + [[BranchLogger shared] logError:@"Invalid queue operation: index out of bound!" error:nil]; return; } if (request) { @@ -94,7 +94,7 @@ - (BNCServerRequest *)removeAt:(NSUInteger)index { @synchronized (self) { BNCServerRequest *request = nil; if (index >= self.queue.count) { - BNCLogError(@"Invalid queue operation: index out of bound!"); + [[BranchLogger shared] logError:@"Invalid queue operation: index out of bound!" error:nil]; return nil; } request = [self.queue objectAtIndex:index]; @@ -120,7 +120,7 @@ - (BNCServerRequest *)peek { - (BNCServerRequest *)peekAt:(NSUInteger)index { @synchronized (self) { if (index >= self.queue.count) { - BNCLogError(@"Invalid queue operation: index out of bound!"); + [[BranchLogger shared] logError:@"Invalid queue operation: index out of bound!" error:nil]; return nil; } BNCServerRequest *request = nil; @@ -167,7 +167,7 @@ - (BOOL)removeInstallOrOpen { BNCServerRequest *request = [self.queue objectAtIndex:i]; // Install extends open, so only need to check open. if ([request isKindOfClass:[BranchOpenRequest class]]) { - BNCLogDebugSDK(@"Removing open request."); + [[BranchLogger shared] logDebug:@"Removing open request."]; ((BranchOpenRequest *)request).callback = nil; [self remove:request]; return YES; @@ -199,7 +199,7 @@ - (BranchOpenRequest *)moveInstallOrOpenToFront:(NSInteger)networkCount { } if (!openOrInstallRequest) { - BNCLogError(@"No install or open request in queue while trying to move it to the front."); + [[BranchLogger shared] logError:@"No install or open request in queue while trying to move it to the front." error:nil]; return nil; } @@ -265,10 +265,10 @@ - (void)persistImmediately { [data writeToURL:self.class.URLForQueueFile options:NSDataWritingAtomic error:&error]; if (error) { - BNCLogError([NSString stringWithFormat:@"Failed to persist queue to disk: %@.", error]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Failed to persist queue to disk: %@.", error] error:error]; } } else { - BNCLogError([NSString stringWithFormat:@"Failed to encode queue."]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Failed to encode queue."] error:nil]; } } } @@ -306,7 +306,7 @@ - (NSData *)archiveObject:(NSObject *)object { data = [NSKeyedArchiver archivedDataWithRootObject:object requiringSecureCoding:YES error:&error]; if (!data && error) { - BNCLogWarning([NSString stringWithFormat:@"Failed to archive: %@", error]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Failed to archive: %@", error]]; } return data; } @@ -356,7 +356,7 @@ - (id)unarchiveObjectFromData:(NSData *)data { id object = [NSKeyedUnarchiver unarchivedObjectOfClasses:[BNCServerRequestQueue encodableClasses] fromData:data error:&error]; if (error) { - BNCLogWarning([NSString stringWithFormat:@"Failed to unarchive: %@", error]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Failed to unarchive: %@", error]]; } return object; @@ -412,7 +412,7 @@ + (instancetype)getInstance { dispatch_once(&onceToken, ^ { sharedQueue = [[BNCServerRequestQueue alloc] init]; [sharedQueue retrieve]; - BNCLogDebugSDK([NSString stringWithFormat:@"Retrieved from storage: %@.", sharedQueue]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Retrieved from storage: %@.", sharedQueue]]; }); return sharedQueue; } diff --git a/BranchSDK/BNCSystemObserver.m b/BranchSDK/BNCSystemObserver.m index cc4944302..9944bb409 100644 --- a/BranchSDK/BNCSystemObserver.m +++ b/BranchSDK/BNCSystemObserver.m @@ -7,7 +7,7 @@ // #import "BNCSystemObserver.h" -#import "BNCLog.h" +#import "BranchLogger.h" #if __has_feature(modules) @import UIKit; @import SystemConfiguration; @@ -54,7 +54,7 @@ + (NSString *)appleAttributionToken { // Apple said this API should respond within 50ms, lets give up after 500 ms dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(500 * NSEC_PER_MSEC))); if (token == nil) { - BNCLogDebug([NSString stringWithFormat:@"AppleAttributionToken request timed out"]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"AppleAttributionToken request timed out"]]; } } #endif diff --git a/BranchSDK/BNCURLFilter.m b/BranchSDK/BNCURLFilter.m index b5a80d4c3..6d7277e7c 100644 --- a/BranchSDK/BNCURLFilter.m +++ b/BranchSDK/BNCURLFilter.m @@ -10,7 +10,7 @@ #import "BNCURLFilter.h" #import "Branch.h" -#import "BNCLog.h" +#import "BranchLogger.h" @interface BNCURLFilter () @@ -58,7 +58,7 @@ - (void)useDefaultPatternList { if (regex && !regexError) { [array addObject:regex]; } else { - BNCLogError([NSString stringWithFormat:@"Invalid regular expression '%@': %@.", pattern, regexError]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Invalid regular expression '%@': %@.", pattern, regexError] error:regexError]; } } return array; @@ -127,12 +127,13 @@ - (BOOL)foundUpdatedURLList:(id)operation { } if (statusCode == 404) { - BNCLogDebug([NSString stringWithFormat:@"No update for URL ignore list found."]); + [[BranchLogger shared] logDebug: [NSString stringWithFormat:@"No update for URL ignore list found."]]; return NO; } else if (statusCode != 200 || error != nil || jsonString == nil) { - BNCLogError([NSString stringWithFormat:@"Failed to update URL ignore list. error: %@ status: %ld", operation.error, (long)operation.response.statusCode]); - BNCLogDebug([NSString stringWithFormat:@"URL ignore JSON: %@", jsonString]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Failed to update URL ignore list. error: %@ status: %ld", operation.error, (long)operation.response.statusCode] error:operation.error]; + [[BranchLogger shared] logDebug: [NSString stringWithFormat:@"URL ignore JSON: %@", jsonString]]; + return NO; } else { @@ -145,19 +146,19 @@ - (nullable NSDictionary *)parseJSONFromData:(NSData *)data { NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; if (error) { - BNCLogError([NSString stringWithFormat:@"Can't parse URL ignore JSON: %@.", error]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Can't parse URL ignore JSON: %@.", error] error:error]; return nil; } NSArray *urls = dictionary[@"uri_skip_list"]; if (![urls isKindOfClass:NSArray.class]) { - BNCLogError([NSString stringWithFormat:@"Can't parse URL ignore JSON, uri_skip_list is not a NSArray."]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Can't parse URL ignore JSON, uri_skip_list is not a NSArray."] error:nil]; return nil; } NSNumber *version = dictionary[@"version"]; if (![version isKindOfClass:NSNumber.class]) { - BNCLogError([NSString stringWithFormat:@"Can't parse URL ignore JSON, version is not a NSNumber."]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Can't parse URL ignore JSON, version is not a NSNumber."] error:nil]; return nil; } diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index 322b09e28..15a2b6d69 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -47,7 +47,6 @@ //#import "BranchQRCode.h" //#import "BNCConfig.h" //#import "NSError+Branch.h" -//#import "BNCLog.h" //#import "BranchConstants.h" //#import "UIViewController+Branch.h" @@ -756,8 +755,6 @@ extern NSString * __nonnull const BNCSpotlightFeature; */ - (void)accountForFacebookSDKPreventingAppLaunch __attribute__((deprecated(("Please ensure application:didFinishLaunchingWithOptions: always returns YES/true instead of using this method. It will be removed in a future release.")))); -- (void)suppressWarningLogs __attribute__((deprecated(("suppressWarningLogs is deprecated and all functionality has been disabled. If you wish to turn off all logging, please invoke BNCLogSetDisplayLevel(BNCLogLevelNone).")))); - /** For use by other Branch SDKs diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index 4f1ce5ce2..d93325fc6 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -39,7 +39,7 @@ #import "BranchEvent.h" #import "BNCPasteboard.h" #import "NSError+Branch.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "UIViewController+Branch.h" #import "BNCReferringURLUtility.h" #import "BNCServerAPI.h" @@ -81,7 +81,6 @@ NSString * const BNCShareInitiatedEvent = @"Share Started"; NSString * const BNCShareCompletedEvent = @"Share Completed"; -static NSString * const BNCLogLevelKey = @"io.branch.sdk.BNCLogLevel"; NSString * const BNCSpotlightFeature = @"spotlight"; #ifndef CSSearchableItemActivityIdentifier @@ -251,14 +250,14 @@ - (id)initWithInterface:(BNCServerInterface *)interface + (void)setNetworkServiceClass:(Class)networkServiceClass { @synchronized ([Branch class]) { if (bnc_networkServiceClass) { - BNCLogError(@"The Branch network service class is already set. It can be set only once."); + [[BranchLogger shared] logError:@"The Branch network service class is already set. It can be set only once." error:nil]; return; } if (![networkServiceClass conformsToProtocol:@protocol(BNCNetworkServiceProtocol)]) { - BNCLogError([NSString stringWithFormat:@"Class '%@' doesn't conform to protocol '%@'.", - NSStringFromClass(networkServiceClass), - NSStringFromProtocol(@protocol(BNCNetworkServiceProtocol))] - ); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Class '%@' doesn't conform to protocol '%@'.", + NSStringFromClass(networkServiceClass), + NSStringFromProtocol(@protocol(BNCNetworkServiceProtocol))] error:nil]; + return; } bnc_networkServiceClass = networkServiceClass; @@ -317,7 +316,7 @@ + (void)resetBranchKey { + (void)setUseTestBranchKey:(BOOL)useTestKey { @synchronized (self) { if (bnc_branchKey && !!useTestKey != !!bnc_useTestBranchKey) { - BNCLogError(@"Can't switch the Branch key once it's in use."); + [[BranchLogger shared] logError:@"Can't switch the Branch key once it's in use." error:nil]; return; } bnc_useTestBranchKey = useTestKey; @@ -335,7 +334,7 @@ + (void)setBranchKey:(NSString *)branchKey { [self setBranchKey:branchKey error:&error]; if (error) { - BNCLogError([NSString stringWithFormat:@"Branch init error: %@", error.localizedDescription]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Branch init error: %@", error.localizedDescription] error:error]; } } @@ -350,6 +349,8 @@ + (void)setBranchKey:(NSString*)branchKey error:(NSError **)error { NSString *errorMessage = [NSString stringWithFormat:@"Branch key can only be set once."]; *error = [NSError branchErrorWithCode:BNCInitError localizedMessage:errorMessage]; + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Branch key can only be set once."] error:*error]; + return; } @@ -358,15 +359,13 @@ + (void)setBranchKey:(NSString*)branchKey error:(NSError **)error { NSString *errorMessage = [NSString stringWithFormat:@"Invalid Branch key of type '%@'.", typeName]; *error = [NSError branchErrorWithCode:BNCInitError localizedMessage:errorMessage]; + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Invalid Branch key of type '%@'.", typeName] error:*error]; return; } if ([branchKey hasPrefix:@"key_test"]) { bnc_useTestBranchKey = YES; - BNCLogWarning( - @"You are using your test app's Branch Key. " - "Remember to change it to live Branch Key for production deployment." - ); + [[BranchLogger shared] logWarning: @"You are using your test app's Branch Key. Remember to change it to live Branch Key for production deployment."]; } else if ([branchKey hasPrefix:@"key_live"]) { bnc_useTestBranchKey = NO; @@ -374,6 +373,7 @@ + (void)setBranchKey:(NSString*)branchKey error:(NSError **)error { } else { NSString *errorMessage = [NSString stringWithFormat:@"Invalid Branch key format. Did you add your Branch key to your Info.plist? Passed key is '%@'.", branchKey]; *error = [NSError branchErrorWithCode:BNCInitError localizedMessage:errorMessage]; + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Invalid Branch key format. Did you add your Branch key to your Info.plist? Passed key is '%@'.", branchKey] error:*error]; return; } @@ -405,9 +405,7 @@ + (NSString *)branchKey { self.branchKey = branchKey; if (!bnc_branchKey) { - BNCLogError(@"Your Branch key is not set in your Info.plist file. See " - "https://dev.branch.io/getting-started/sdk-integration-guide/guide/ios/#configure-xcode-project" - " for configuration instructions."); + [[BranchLogger shared] logError:@"Your Branch key is not set in your Info.plist file. See https://dev.branch.io/getting-started/sdk-integration-guide/guide/ios/#configure-xcode-project for configuration instructions." error:nil]; } return bnc_branchKey; } @@ -471,11 +469,6 @@ - (void)accountForFacebookSDKPreventingAppLaunch { // deprecated } -- (void)suppressWarningLogs { - NSLog(@"suppressWarningLogs is deprecated and all functionality has been disabled. " - "If you wish to turn off all logging, please invoke BNCLogSetDisplayLevel(BNCLogLevelNone)."); -} - - (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value { [self.preferenceHelper setRequestMetadataKey:key value:value]; } @@ -792,8 +785,6 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity { } - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSString *)sceneIdentifier { - BNCLogDebugSDK(@"continueUserActivity:"); - if (userActivity.referrerURL) { self.preferenceHelper.initialReferrer = userActivity.referrerURL.absoluteString; } @@ -949,7 +940,7 @@ - (void)handleATTAuthorizationStatus:(NSUInteger)status { - (void)setSKAdNetworkCalloutMaxTimeSinceInstall:(NSTimeInterval)maxTimeInterval { if (@available(iOS 16.1, macCatalyst 16.1, *)) { - BNCLogDebug(@"This is no longer supported for iOS 16.1+ - SKAN4.0"); + [[BranchLogger shared] logDebug:@"This is no longer supported for iOS 16.1+ - SKAN4.0"]; } else { [BNCSKAdNetwork sharedInstance].maxTimeSinceInstall = maxTimeInterval; } @@ -1021,7 +1012,7 @@ - (void)logoutWithCallback:(callbackWithStatus)callback { (Branch.trackingDisabled) ? [NSError branchErrorWithCode:BNCTrackingDisabledError] : [NSError branchErrorWithCode:BNCInitError]; - BNCLogError(@"Branch is not initialized, cannot logout."); + [[BranchLogger shared] logError:@"Branch is not initialized, cannot logout." error:error]; if (callback) {callback(NO, error);} return; } @@ -1431,7 +1422,7 @@ - (void)passPasteItemProviders:(NSArray *)itemProviders { // 2. Check if URL is branch URL and if yes -> store it. [item loadItemForTypeIdentifier:UTTypeURL.identifier options:NULL completionHandler:^(NSURL *url, NSError * _Null_unspecified error) { if (error) { - BNCLogError([NSString stringWithFormat:@"%@", error]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"%@", error] error:error]; } else if ([Branch isBranchLink:url.absoluteString]) { [self.preferenceHelper setLocalUrl:[url absoluteString]]; @@ -1457,8 +1448,7 @@ + (Branch *)getInstanceInternal:(NSString *)key { // If there was stored key and it isn't the same as the currently used (or doesn't exist), we need to clean up // Note: Link Click Identifier is not cleared because of the potential for that to mess up a deep link if (preferenceHelper.lastRunBranchKey && ![key isEqualToString:preferenceHelper.lastRunBranchKey]) { - BNCLogWarning(@"The Branch Key has changed, clearing relevant items."); - + [[BranchLogger shared] logWarning:@"The Branch Key has changed, clearing relevant items."]; preferenceHelper.appVersion = nil; preferenceHelper.randomizedDeviceToken = nil; preferenceHelper.sessionID = nil; @@ -1584,7 +1574,7 @@ - (NSString *)generateShortUrl:(NSArray *)tags linkData:linkData linkCache:self.linkCache]; - BNCLogDebug(@"Creating a custom URL synchronously."); + [[BranchLogger shared] logDebug:@"Creating a custom URL synchronously."]; BNCServerResponse *serverResponse = [req makeRequest:self.serverInterface key:self.class.branchKey]; shortURL = [req processResponse:serverResponse]; @@ -1734,7 +1724,7 @@ - (void)applicationWillResignActive { self.initializationStatus = BNCInitStatusUninitialized; [self.requestQueue persistImmediately]; [BranchOpenRequest setWaitNeededForOpenResponseLock]; - BNCLogDebugSDK(@"Application resigned active."); + [[BranchLogger shared] logDebug:@"Application resigned active."]; } } @@ -1798,8 +1788,7 @@ - (void) processRequest:(BNCServerRequest*)req } // On network problems, or Branch down, call the other callbacks and stop processing. else { - BNCLogDebugSDK(@"Network error: failing queued requests."); - + [[BranchLogger shared] logDebug:@"Network error: failing queued requests."]; // First, gather all the requests to fail NSMutableArray *requestsToFail = [[NSMutableArray alloc] init]; for (int i = 0; i < self.requestQueue.queueDepth; i++) { @@ -1871,7 +1860,7 @@ - (void)processNextQueueItem { // If tracking is disabled, then do not check for install event. It won't exist. if (!Branch.trackingDisabled) { if (![req isKindOfClass:[BranchInstallRequest class]] && !self.preferenceHelper.randomizedBundleToken) { - BNCLogError(@"User session has not been initialized!"); + [[BranchLogger shared] logError:@"User session has not been initialized!" error:nil]; BNCPerformBlockOnMainThreadSync(^{ [req processResponse:nil error:[NSError branchErrorWithCode:BNCInitError]]; }); @@ -1879,7 +1868,7 @@ - (void)processNextQueueItem { } else if (![req isKindOfClass:[BranchOpenRequest class]] && (!self.preferenceHelper.randomizedDeviceToken || !self.preferenceHelper.sessionID)) { - BNCLogError(@"Missing session items!"); + [[BranchLogger shared] logError:@"Missing session items!" error:nil]; BNCPerformBlockOnMainThreadSync(^{ [req processResponse:nil error:[NSError branchErrorWithCode:BNCInitError]]; }); @@ -1942,7 +1931,7 @@ - (void)notifyNativeToInit { // Some methods require init before they are called. Instead of returning an error, we try to fix the situation by calling init ourselves. - (void)initSafetyCheck { if (self.initializationStatus == BNCInitStatusUninitialized) { - BNCLogDebug(@"Branch avoided an error by preemptively initializing."); + [[BranchLogger shared] logDebug:@"Branch avoided an error by preemptively initializing."]; [self initUserSessionAndCallCallback:NO sceneIdentifier:nil]; } } @@ -1952,8 +1941,6 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr // ignore lifecycle calls while waiting for a plugin runtime. @synchronized (self) { if (self.deferInitForPluginRuntime) { - //NSString *debug = [NSString stringWithFormat:@"Init is deferred, ignoring call: %@", NSThread.callStackSymbols]; - //BNCLogDebug(debug); return; } } @@ -1966,18 +1953,6 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr urlstring = self.preferenceHelper.externalIntentURI; } - if (urlstring.length) { - NSArray *queryItems = [BNCEncodingUtils queryItems:[NSURL URLWithString:urlstring]]; - for (BNCKeyValue*item in queryItems) { - if ([item.key isEqualToString:@"BranchLogLevel"]) { - BNCLogLevel logLevel = BNCLogLevelFromString(item.value); - [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:logLevel] forKey:BNCLogLevelKey]; - BNCLogSetDisplayLevel(logLevel); - NSLog(@"[io.branch.sdk] BNCLogLevel set to %ld.", (long) logLevel); - } - } - } - // If the session is not yet initialized if (self.initializationStatus == BNCInitStatusUninitialized) { [self initializeSessionAndCallCallback:callCallback sceneIdentifier:sceneIdentifier]; @@ -2115,8 +2090,7 @@ - (void)automaticallyDeeplinkWithReferringParams:(NSDictionary *)latestReferring [branchSharingController configureControlWithData:latestReferringParams]; } else { - BNCLogWarning([NSString stringWithFormat:@"The automatic deeplink view controller '%@' for key '%@' does not implement 'configureControlWithData:'.", - branchSharingController, key]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"The automatic deeplink view controller '%@' for key '%@' does not implement 'configureControlWithData:'.", branchSharingController, key]]; } self.deepLinkPresentingController = [UIViewController bnc_currentViewController]; @@ -2128,7 +2102,7 @@ - (void)automaticallyDeeplinkWithReferringParams:(NSDictionary *)latestReferring [branchSharingController configureControlWithData:latestReferringParams]; } else { - BNCLogWarning(@"View controller does not implement configureControlWithData:"); + [[BranchLogger shared] logWarning:@"View controller does not implement configureControlWithData:"]; } branchSharingController.deepLinkingCompletionDelegate = self; switch (deepLinkInstance.option) { @@ -2190,7 +2164,7 @@ - (void)automaticallyDeeplinkWithReferringParams:(NSDictionary *)latestReferring [branchSharingController configureControlWithData:latestReferringParams]; } else { - BNCLogWarning(@"View controller does not implement configureControlWithData:"); + [[BranchLogger shared] logWarning:@"View controller does not implement configureControlWithData:"]; } branchSharingController.deepLinkingCompletionDelegate = self; if ([self.deepLinkPresentingController presentedViewController]) { diff --git a/BranchSDK/BranchCSSearchableItemAttributeSet.m b/BranchSDK/BranchCSSearchableItemAttributeSet.m index 01802dbf1..0465b81f7 100644 --- a/BranchSDK/BranchCSSearchableItemAttributeSet.m +++ b/BranchSDK/BranchCSSearchableItemAttributeSet.m @@ -10,7 +10,7 @@ #import "NSError+Branch.h" #import "BranchConstants.h" #import "BranchConstants.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "Branch.h" #import "BNCSystemObserver.h" @@ -45,7 +45,7 @@ - (instancetype)initWithItemContentType:(nonnull NSString *)type { - (void)setIdentifier:(NSString *)identifier { if (![identifier hasPrefix:BRANCH_SPOTLIGHT_PREFIX]) { - BNCLogWarning(@"Do not set BranchCSSearchableItemAttributeSet's identifier. It will be overwritten."); + [[BranchLogger shared] logWarning:@"Do not set BranchCSSearchableItemAttributeSet's identifier. It will be overwritten."]; } } diff --git a/BranchSDK/BranchContentDiscoverer.m b/BranchSDK/BranchContentDiscoverer.m index b8ab1da9c..c9fa3394e 100644 --- a/BranchSDK/BranchContentDiscoverer.m +++ b/BranchSDK/BranchContentDiscoverer.m @@ -13,7 +13,7 @@ #import "BNCPreferenceHelper.h" #import "BranchConstants.h" #import "BNCEncodingUtils.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "UIViewController+Branch.h" @interface BranchContentDiscoverer () @@ -51,7 +51,7 @@ - (void) startDiscoveryTaskWithManifest:(BranchContentDiscoveryManifest*)manifes - (void)startDiscoveryTask { if (![NSThread isMainThread]) { - BNCLogError(@"Discovery should be called on main thread."); + [[BranchLogger shared] logError:@"Discovery should be called on main thread." error:nil]; } [_contentDiscoveryTimer invalidate]; _contentDiscoveryTimer = diff --git a/BranchSDK/BranchEvent.m b/BranchSDK/BranchEvent.m index a7c9703cf..d28d0d568 100644 --- a/BranchSDK/BranchEvent.m +++ b/BranchSDK/BranchEvent.m @@ -9,7 +9,7 @@ #import "BranchEvent.h" #import "BranchConstants.h" #import "NSError+Branch.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "BNCCallbackMap.h" #import "BNCReachability.h" #import "BNCSKAdNetwork.h" @@ -96,14 +96,13 @@ - (void)processResponse:(BNCServerResponse*)response error:(NSError*)error { BOOL lockWin = [[BNCSKAdNetwork sharedInstance] getLockedStatusFromDataResponse:dictionary]; BOOL shouldCallUpdatePostback = [[BNCSKAdNetwork sharedInstance] shouldCallPostbackForDataResponse:dictionary]; - BNCLogDebug([NSString stringWithFormat:@"SKAN 4.0 params - conversionValue:%@ coarseValue:%@, locked:%d, shouldCallPostback:%d, currentWindow:%d, firstAppLaunchTime: %@", conversionValue, coarseConversionValue, lockWin, shouldCallUpdatePostback, (int)[BNCPreferenceHelper sharedInstance].skanCurrentWindow, [BNCPreferenceHelper sharedInstance].firstAppLaunchTime]); - + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"SKAN 4.0 params - conversionValue:%@ coarseValue:%@, locked:%d, shouldCallPostback:%d, currentWindow:%d, firstAppLaunchTime: %@", conversionValue, coarseConversionValue, lockWin, shouldCallUpdatePostback, (int)[BNCPreferenceHelper sharedInstance].skanCurrentWindow, [BNCPreferenceHelper sharedInstance].firstAppLaunchTime]]; if(shouldCallUpdatePostback){ [[BNCSKAdNetwork sharedInstance] updatePostbackConversionValue: conversionValue.longValue coarseValue:coarseConversionValue lockWindow:lockWin completionHandler:^(NSError * _Nullable error) { if (error) { - BNCLogError([NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]] error:error]; } else { - BNCLogDebug([NSString stringWithFormat:@"Update conversion value was successful. Conversion Value - %@", conversionValue]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Update conversion value was successful. Conversion Value - %@", conversionValue]]; } }]; } @@ -111,9 +110,9 @@ - (void)processResponse:(BNCServerResponse*)response error:(NSError*)error { } else if (@available(iOS 15.4, macCatalyst 15.4, *)) { [[BNCSKAdNetwork sharedInstance] updatePostbackConversionValue:conversionValue.intValue completionHandler: ^(NSError *error){ if (error) { - BNCLogError([NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]] error:error]; } else { - BNCLogDebug([NSString stringWithFormat:@"Update conversion value was successful. Conversion Value - %@", conversionValue]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Update conversion value was successful. Conversion Value - %@", conversionValue]]; } }]; } else { @@ -277,7 +276,8 @@ - (NSDictionary*) dictionary { - (void)logEventWithCompletion:(void (^_Nullable)(BOOL success, NSError * _Nullable error))completion { if (![_eventName isKindOfClass:[NSString class]] || _eventName.length == 0) { - BNCLogError([NSString stringWithFormat:@"Invalid event type '%@' or empty string.", NSStringFromClass(_eventName.class)]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Invalid event type '%@' or empty string.", NSStringFromClass(_eventName.class)] error:nil]; + if (completion) { NSError *error = [NSError branchErrorWithCode:BNCGeneralError localizedMessage: @"Invalid event type"]; completion(NO, error); @@ -453,15 +453,15 @@ - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu } [self logEvent]; - BNCLogDebug([NSString stringWithFormat:@"Created and logged event from transaction: %@", self.description]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Created and logged event from transaction: %@", self.description]]; } else { - BNCLogError([NSString stringWithFormat:@"Unable to log Branch event from transaction. No products were found with the product ID."]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Unable to log Branch event from transaction. No products were found with the product ID."] error:nil]; } }); } - (void)request:(SKRequest *)request didFailWithError:(NSError *)error { - BNCLogError([NSString stringWithFormat:@"Product request failed: %@", error]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Product request failed: %@", error] error:error]; [[BNCEventUtils shared] removeEvent:self]; } diff --git a/BranchSDK/BranchJsonConfig.m b/BranchSDK/BranchJsonConfig.m index cf40aacec..aa3bbb077 100644 --- a/BranchSDK/BranchJsonConfig.m +++ b/BranchSDK/BranchJsonConfig.m @@ -6,7 +6,7 @@ // // -#import "BNCLog.h" +#import "BranchLogger.h" #import "BranchJsonConfig.h" NSString * _Nonnull const BranchJsonConfigDebugModeOption = @"debugMode"; @@ -56,12 +56,13 @@ - (void)loadConfigFile NSError *error; id object = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; if (!object || error) { - BNCLogError([NSString stringWithFormat:@"Failed to parse branch.json. Error: %@", error.localizedDescription]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Failed to parse branch.json. Error: %@", error.localizedDescription] error:error]; return; } if (![object isKindOfClass:NSDictionary.class]) { - BNCLogError(@"Contents of branch.json should be a JSON object."); + [[BranchLogger shared] logError:@"Contents of branch.json should be a JSON object." error:nil]; + return; } @@ -71,12 +72,11 @@ - (void)loadConfigFile - (NSData *)configFileContents { if (!self.configFileURL) return nil; - BNCLogDebug([NSString stringWithFormat:@"Loading %@", self.configFileURL.pathComponents.lastObject]); - + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Loading %@", self.configFileURL.pathComponents.lastObject]]; NSError *error; NSData *data = [NSData dataWithContentsOfURL:self.configFileURL options:0 error:&error]; if (!data || error) { - BNCLogError([NSString stringWithFormat:@"Failed to load %@. Error: %@", self.configFileURL, error.localizedDescription]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Failed to load %@. Error: %@", self.configFileURL, error.localizedDescription] error:error]; return nil; } return data; @@ -109,7 +109,7 @@ - (void)findConfigFile } if (!configFileURL) { - BNCLogDebug(@"No branch.json in app bundle."); + [[BranchLogger shared] logDebug:@"No branch.json in app bundle."]; return; } diff --git a/BranchSDK/BranchLastAttributedTouchData.m b/BranchSDK/BranchLastAttributedTouchData.m index 2193e943b..99316a32d 100644 --- a/BranchSDK/BranchLastAttributedTouchData.m +++ b/BranchSDK/BranchLastAttributedTouchData.m @@ -9,7 +9,7 @@ #import "BranchLastAttributedTouchData.h" #import "BranchLATDRequest.h" #import "BNCJSONUtility.h" -#import "BNCLog.h" +#import "BranchLogger.h" @implementation BranchLastAttributedTouchData @@ -33,7 +33,7 @@ + (void)requestLastTouchAttributedData:(BNCServerInterface *)serverInterface key if (window > -1 && window < 365) { request.attributionWindow = window; } else { - BNCLogWarning(@"Attribution window is outside the expected range, using 30 days."); + [[BranchLogger shared] logWarning:@"Attribution window is outside the expected range, using 30 days."]; } [request makeRequest:serverInterface key:key callback:^(BNCServerResponse *response, NSError *error) { diff --git a/BranchSDK/BranchOpenRequest.m b/BranchSDK/BranchOpenRequest.m index 2b2ec894c..89517f15f 100644 --- a/BranchSDK/BranchOpenRequest.m +++ b/BranchSDK/BranchOpenRequest.m @@ -20,7 +20,7 @@ // handle app clip data for installs. This shouldn't be here imho #import "BNCAppGroupsData.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "BNCRequestFactory.h" #import "BNCServerAPI.h" @@ -102,17 +102,14 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { if (sessionData == nil || [sessionData isKindOfClass:[NSString class]]) { } else if ([sessionData isKindOfClass:[NSDictionary class]]) { - BNCLogWarning([NSString stringWithFormat:@"Received session data of type '%@' data is '%@'.", - NSStringFromClass(sessionData.class), sessionData]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Received session data of type '%@' data is '%@'.", NSStringFromClass(sessionData.class), sessionData]]; sessionData = [BNCEncodingUtils encodeDictionaryToJsonString:(NSDictionary*)sessionData]; } else if ([sessionData isKindOfClass:[NSArray class]]) { - BNCLogWarning([NSString stringWithFormat:@"Received session data of type '%@' data is '%@'.", - NSStringFromClass(sessionData.class), sessionData]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Received session data of type '%@' data is '%@'.", NSStringFromClass(sessionData.class), sessionData]]; sessionData = [BNCEncodingUtils encodeArrayToJsonString:(NSArray*)sessionData]; } else { - BNCLogError([NSString stringWithFormat:@"Received session data of type '%@' data is '%@'.", - NSStringFromClass(sessionData.class), sessionData]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Received session data of type '%@' data is '%@'.", NSStringFromClass(sessionData.class), sessionData] error:error]; sessionData = nil; } @@ -193,17 +190,17 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { [[BNCSKAdNetwork sharedInstance] updatePostbackConversionValue:0 coarseValue:defaultCoarseConValue lockWindow:NO completionHandler:^(NSError * _Nullable error) { if (error) { - BNCLogError([NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]] error:error]; } else { - BNCLogDebug([NSString stringWithFormat:@"Update conversion value was successful for INSTALL Event"]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Update conversion value was successful for INSTALL Event"]]; } }]; } else if (@available(iOS 15.4, macCatalyst 15.4, *)){ [[BNCSKAdNetwork sharedInstance] updatePostbackConversionValue:0 completionHandler:^(NSError * _Nullable error) { if (error) { - BNCLogError([NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]] error:error]; } else { - BNCLogDebug([NSString stringWithFormat:@"Update conversion value was successful for INSTALL Event"]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Update conversion value was successful for INSTALL Event"]]; } }]; } @@ -225,23 +222,23 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { BOOL lockWin = [[BNCSKAdNetwork sharedInstance] getLockedStatusFromDataResponse:data]; BOOL shouldCallUpdatePostback = [[BNCSKAdNetwork sharedInstance] shouldCallPostbackForDataResponse:data]; - BNCLogDebug([NSString stringWithFormat:@"SKAN 4.0 params - conversionValue:%@ coarseValue:%@, locked:%d, shouldCallPostback:%d, currentWindow:%d, firstAppLaunchTime: %@", conversionValue, coarseConversionValue, lockWin, shouldCallUpdatePostback, (int)preferenceHelper.skanCurrentWindow, preferenceHelper.firstAppLaunchTime]); + [[BranchLogger shared] logDebug: [NSString stringWithFormat:@"SKAN 4.0 params - conversionValue:%@ coarseValue:%@, locked:%d, shouldCallPostback:%d, currentWindow:%d, firstAppLaunchTime: %@", conversionValue, coarseConversionValue, lockWin, shouldCallUpdatePostback, (int)preferenceHelper.skanCurrentWindow, preferenceHelper.firstAppLaunchTime]]; if(shouldCallUpdatePostback){ [[BNCSKAdNetwork sharedInstance] updatePostbackConversionValue: conversionValue.longValue coarseValue:coarseConversionValue lockWindow:lockWin completionHandler:^(NSError * _Nullable error) { if (error) { - BNCLogError([NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]] error:error]; } else { - BNCLogDebug([NSString stringWithFormat:@"Update conversion value was successful. Conversion Value - %@", conversionValue]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Update conversion value was successful. Conversion Value - %@", conversionValue]]; } }]; } } else if (@available(iOS 15.4, macCatalyst 15.4, *)) { [[BNCSKAdNetwork sharedInstance] updatePostbackConversionValue:conversionValue.intValue completionHandler: ^(NSError *error){ if (error) { - BNCLogError([NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Update conversion value failed with error - %@", [error description]] error:error]; } else { - BNCLogDebug([NSString stringWithFormat:@"Update conversion value was successful. Conversion Value - %@", conversionValue]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Update conversion value was successful. Conversion Value - %@", conversionValue]]; } }]; } else { @@ -284,7 +281,7 @@ + (void) initialize { + (void) setWaitNeededForOpenResponseLock { @synchronized (self) { if (!openRequestWaitQueueIsSuspended) { - BNCLogDebugSDK(@"Suspended for openRequestWaitQueue."); + [[BranchLogger shared] logDebug:@"Suspended for openRequestWaitQueue."]; openRequestWaitQueueIsSuspended = YES; dispatch_suspend(openRequestWaitQueue); } @@ -292,16 +289,16 @@ + (void) setWaitNeededForOpenResponseLock { } + (void) waitForOpenResponseLock { - BNCLogDebugSDK(@"Waiting for openRequestWaitQueue."); + [[BranchLogger shared] logDebug:@"Waiting for openRequestWaitQueue."]; dispatch_sync(openRequestWaitQueue, ^ { - BNCLogDebugSDK(@"Finished waitForOpenResponseLock."); + [[BranchLogger shared] logDebug:@"Finished waitForOpenResponseLock."]; }); } + (void) releaseOpenResponseLock { @synchronized (self) { if (openRequestWaitQueueIsSuspended) { - BNCLogDebugSDK(@"Resuming openRequestWaitQueue."); + [[BranchLogger shared] logDebug:@"Resuming openRequestWaitQueue."]; openRequestWaitQueueIsSuspended = NO; dispatch_resume(openRequestWaitQueue); } diff --git a/BranchSDK/BranchPluginSupport.m b/BranchSDK/BranchPluginSupport.m index ca07797ed..5f77ba81c 100644 --- a/BranchSDK/BranchPluginSupport.m +++ b/BranchSDK/BranchPluginSupport.m @@ -11,7 +11,6 @@ #import "BNCDeviceInfo.h" #import "BNCPreferenceHelper.h" #import "Branch.h" -#import "BNCLog.h" #import "BNCConfig.h" @implementation BranchPluginSupport diff --git a/BranchSDK/BranchQRCode.m b/BranchSDK/BranchQRCode.m index 6000e6a1a..1e55e35e4 100644 --- a/BranchSDK/BranchQRCode.m +++ b/BranchSDK/BranchQRCode.m @@ -13,7 +13,7 @@ #import "BranchConstants.h" #import "NSError+Branch.h" #import "UIViewController+Branch.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "BNCServerAPI.h" @interface BranchQRCode() @@ -35,11 +35,11 @@ - (instancetype) init { - (void) setMargin:(NSNumber *)margin { if (margin.intValue > 20) { margin = @(20); - BNCLogWarning(@"Margin was reduced to the maximum of 20."); + [[BranchLogger shared] logWarning:@"QR code margin was reduced to the maximum of 20."]; } if (margin.intValue < 1) { margin = @(1); - BNCLogWarning(@"Margin was increased to the minimum of 1."); + [[BranchLogger shared] logWarning:@"QR code margin was increased to the minimum of 1."]; } _margin = margin; } @@ -47,11 +47,11 @@ - (void) setMargin:(NSNumber *)margin { - (void) setWidth:(NSNumber *)width { if (width.intValue > 2000) { width = @(2000); - BNCLogWarning(@"Width was reduced to the maximum of 2000."); + [[BranchLogger shared] logWarning:@"QR code width was reduced to the maximum of 2000."]; } if (width.intValue < 300) { width = @(300); - BNCLogWarning(@"Width was increased to the minimum of 500."); + [[BranchLogger shared] logWarning:@"QR code width was increased to the minimum of 500."]; } _width = width; } @@ -73,7 +73,7 @@ - (void)getQRCodeAsData:(nullable BranchUniversalObject *)buo NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString: self.centerLogo]]; UIImage *image=[UIImage imageWithData:data]; if (image == nil) { - BNCLogWarning(@"QR code center logo was an invalid URL string."); + [[BranchLogger shared] logWarning:@"QR code center logo was an invalid URL string."]; } else { settings[@"center_logo_url"] = self.centerLogo; } @@ -137,14 +137,13 @@ - (void)callQRCodeAPI:(nullable NSDictionary *)params NSData *postData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; [request setHTTPBody:postData]; - BNCLogDebug([NSString stringWithFormat:@"Network start operation %@.", request.URL.absoluteString]); - + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Network start operation %@.", request.URL.absoluteString]]; NSDate *startDate = [NSDate date]; NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { - BNCLogError([NSString stringWithFormat:@"QR Code Post Request Error: %@", [error localizedDescription]]); + [[BranchLogger shared] logError:[NSString stringWithFormat:@"QR Code Post Request Error: %@", [error localizedDescription]] error:error]; completion(nil, error); return; } @@ -153,25 +152,23 @@ - (void)callQRCodeAPI:(nullable NSDictionary *)params if (httpResponse.statusCode == 200) { - BNCLogDebug([NSString stringWithFormat:@"Network finish operation %@ %1.3fs. Status %ld.", - request.URL.absoluteString, - [[NSDate date] timeIntervalSinceDate:startDate], - (long)httpResponse.statusCode]); + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Network finish operation %@ %1.3fs. Status %ld.", + request.URL.absoluteString, + [[NSDate date] timeIntervalSinceDate:startDate], + (long)httpResponse.statusCode]]; completion(data, nil); } else { NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; - BNCLogError([NSString stringWithFormat:@"Network finish operation %@ %1.3fs. Status %ld error %@.\n%@.", - request.URL.absoluteString, - [[NSDate date] timeIntervalSinceDate:startDate], - (long)httpResponse.statusCode, - error, - responseDictionary]); - error = [NSError branchErrorWithCode: BNCBadRequestError localizedMessage: responseDictionary[@"message"]]; - + [[BranchLogger shared] logError:[NSString stringWithFormat:@"Network finish operation %@ %1.3fs. Status %ld error %@.\n%@.", + request.URL.absoluteString, + [[NSDate date] timeIntervalSinceDate:startDate], + (long)httpResponse.statusCode, + error, + responseDictionary] error:error]; completion(nil, error); } }]; @@ -208,7 +205,7 @@ - (void)showShareSheetWithQRCodeFromViewController:(nullable UIViewController *) } if (!presentingViewController) { - BNCLogError(@"No view controller is present to show the share sheet. Not showing sheet."); + [[BranchLogger shared] logError:@"No view controller is present to show the share sheet. Not showing sheet." error:nil]; return; } diff --git a/BranchSDK/BranchScene.m b/BranchSDK/BranchScene.m index eca3d011a..f6c8480b4 100644 --- a/BranchSDK/BranchScene.m +++ b/BranchSDK/BranchScene.m @@ -8,7 +8,7 @@ #import "BranchScene.h" #import "Branch.h" -#import "BNCLog.h" +#import "BranchLogger.h" @implementation BranchScene @@ -40,7 +40,7 @@ - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivi - (void)scene:(UIScene *)scene openURLContexts:(NSSet *)URLContexts NS_EXTENSION_UNAVAILABLE("BranchScene does not support Extensions") { if (URLContexts.count != 1) { - BNCLogWarning(@"Branch only supports a single URLContext"); + [[BranchLogger shared] logWarning:@"Branch only supports a single URLContext"]; } UIOpenURLContext *context = [URLContexts allObjects].firstObject; diff --git a/BranchSDK/BranchShareLink.m b/BranchSDK/BranchShareLink.m index c6f1eef7a..2cd4b874b 100644 --- a/BranchSDK/BranchShareLink.m +++ b/BranchSDK/BranchShareLink.m @@ -9,7 +9,7 @@ #import "BranchShareLink.h" #import "BranchConstants.h" #import "BranchActivityItemProvider.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "Branch.h" #import "BranchEvent.h" #import "UIViewController+Branch.h" @@ -115,10 +115,7 @@ - (void) shareDidComplete:(BOOL)completed activityError:(NSError*)error { // Make sure we can share if (!(self.universalObject.canonicalIdentifier || self.universalObject.canonicalUrl || self.universalObject.title)) { - BNCLogWarning(@"A canonicalIdentifier, canonicalURL, or title are required to uniquely" - " identify content. In order to not break the end user experience with sharing," - " Branch SDK will proceed to create a URL, but content analytics may not properly" - " include this URL."); + [[BranchLogger shared] logWarning:@"A canonicalIdentifier, canonicalURL, or title are required to uniquely identify content. In order to not break the end user experience with sharing, Branch SDK will proceed to create a URL, but content analytics may not properly include this URL."]; } self.serverParameters = [[self.universalObject getParamsForServerRequestWithAddedLinkProperties:self.linkProperties] mutableCopy]; @@ -204,9 +201,7 @@ - (void) presentActivityViewControllerFromViewController:(UIViewController*_Null [shareViewController setValue:emailSubject forKey:@"subject"]; } @catch (NSException*) { - BNCLogWarning( - @"Unable to setValue 'emailSubject' forKey 'subject' on UIActivityViewController." - ); + [[BranchLogger shared] logWarning: @"Unable to setValue 'emailSubject' forKey 'subject' on UIActivityViewController."]; } } @@ -221,7 +216,7 @@ - (void) presentActivityViewControllerFromViewController:(UIViewController*_Null } if (!presentingViewController) { - BNCLogError(@"No view controller is present to show the share sheet. Not showing sheet."); + [[BranchLogger shared] logError:@"No view controller is present to show the share sheet. Not showing sheet." error:nil]; return; } diff --git a/BranchSDK/BranchShortUrlSyncRequest.m b/BranchSDK/BranchShortUrlSyncRequest.m index 2526af572..8f026b8df 100644 --- a/BranchSDK/BranchShortUrlSyncRequest.m +++ b/BranchSDK/BranchShortUrlSyncRequest.m @@ -11,7 +11,7 @@ #import "BNCEncodingUtils.h" #import "BranchConstants.h" #import "BNCConfig.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "BNCRequestFactory.h" #import "BNCServerAPI.h" @@ -62,8 +62,8 @@ - (BNCServerResponse *)makeRequest:(BNCServerInterface *)serverInterface key:(NS - (NSString *)processResponse:(BNCServerResponse *)response { if (![response.statusCode isEqualToNumber:@200]) { - BNCLogWarning([NSString stringWithFormat:@"Short link creation received HTTP status code %@. Using long link instead.", - response.statusCode]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Short link creation received HTTP status code %@. Using long link instead.", + response.statusCode]]; NSString *failedUrl = nil; NSString *userUrl = [BNCPreferenceHelper sharedInstance].userUrl; if (userUrl) { diff --git a/BranchSDK/BranchUniversalObject.m b/BranchSDK/BranchUniversalObject.m index 8ac43afc6..26cf5d21e 100644 --- a/BranchSDK/BranchUniversalObject.m +++ b/BranchSDK/BranchUniversalObject.m @@ -9,7 +9,7 @@ #import "BranchUniversalObject.h" #import "NSError+Branch.h" #import "BranchConstants.h" -#import "BNCLog.h" +#import "BranchLogger.h" #import "BNCEncodingUtils.h" #import "Branch.h" #import "BranchEvent.h" @@ -337,7 +337,7 @@ - (void)registerViewWithCallback:(callbackWithParams)callback { if (!self.canonicalIdentifier && !self.title) { NSString *message = @"Could not register view."; NSError *error = [NSError branchErrorWithCode:BNCContentIdentifierError localizedMessage:message]; - BNCLogWarning([NSString stringWithFormat:@"%@", error]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"%@", error]]; if (callback) callback([[NSDictionary alloc] init], error); return; } @@ -356,7 +356,8 @@ - (void)registerViewWithCallback:(callbackWithParams)callback { - (NSString *)getShortUrlWithLinkProperties:(BranchLinkProperties *)linkProperties { if (!self.canonicalIdentifier && !self.title) { - BNCLogWarning(@"A canonicalIdentifier or title are required to uniquely identify content, so could not generate a URL."); + [[BranchLogger shared] logWarning:@"A canonicalIdentifier or title are required to uniquely identify content, so could not generate a URL."]; + return nil; } @@ -374,7 +375,7 @@ - (void)getShortUrlWithLinkProperties:(BranchLinkProperties *)linkProperties and if (!self.canonicalIdentifier && !self.title) { NSString *message = @"Could not generate a URL."; NSError *error = [NSError branchErrorWithCode:BNCContentIdentifierError localizedMessage:message]; - BNCLogWarning([NSString stringWithFormat:@"%@", error]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"%@", error]]; if (callback) callback([BNCPreferenceHelper sharedInstance].userUrl, error); return; } @@ -394,7 +395,7 @@ - (NSString *)getShortUrlWithLinkPropertiesAndIgnoreFirstClick:(BranchLinkProper if (!self.canonicalIdentifier && !self.title) { NSString *message = @"Could not generate a URL."; NSError *error = [NSError branchErrorWithCode:BNCContentIdentifierError localizedMessage:message]; - BNCLogWarning([NSString stringWithFormat:@"%@", error]); + [[BranchLogger shared] logWarning:[NSString stringWithFormat:@"%@", error]]; return nil; } From 6bc64c86da8bf3c86fc12eb13b02375c6bb46a13 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Tue, 13 Feb 2024 10:42:28 -0800 Subject: [PATCH 06/16] Added method to set API URL --- Branch-TestBed/Branch-TestBed/AppDelegate.m | 5 ++++- BranchSDK/BNCPreferenceHelper.m | 9 ++++----- BranchSDK/BNCServerAPI.m | 7 +++++++ BranchSDK/Branch.h | 6 ++++++ BranchSDK/Branch.m | 4 ++++ BranchSDK/BranchPluginSupport.m | 1 - 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index 09925169f..d59683f7d 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -34,7 +34,10 @@ - (BOOL)application:(UIApplication *)application // Branch.useTestBranchKey = YES; // Make sure to comment this line out for production apps!!! Branch *branch = [Branch getInstance]; - + + // Change the Branch base API URL + //[branch setAPIUrl:@"https://api3.branch.io"]; + // test pre init support //[self testDispatchToIsolationQueue:branch] diff --git a/BranchSDK/BNCPreferenceHelper.m b/BranchSDK/BNCPreferenceHelper.m index fb7a3ca58..dfb9e27cd 100644 --- a/BranchSDK/BNCPreferenceHelper.m +++ b/BranchSDK/BNCPreferenceHelper.m @@ -26,7 +26,7 @@ static NSString * const BRANCH_PREFS_KEY_LAST_RUN_BRANCH_KEY = @"bnc_last_run_branch_key"; static NSString * const BRANCH_PREFS_KEY_LAST_STRONG_MATCH_DATE = @"bnc_strong_match_created_date"; -static NSString * const BRANCH_PREFS_KEY_API_URL = @"bnc_api_url"; +static NSString * const BRANCH_PREFS_KEY_CUSTOM_API_URL = @"bnc_custom_api_url"; static NSString * const BRANCH_PREFS_KEY_PATTERN_LIST_URL = @"bnc_pattern_list_url"; static NSString * const BRANCH_PREFS_KEY_RANDOMIZED_DEVICE_TOKEN = @"bnc_randomized_device_token"; @@ -160,24 +160,23 @@ - (void)setBranchAPIURL:(NSString *)url { if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ @synchronized (self) { _branchAPIURL = [url copy]; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_API_URL value:_branchAPIURL]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL]; } } else { BNCLogWarning(@"Ignoring invalid custom API URL"); } } -// TODO: This method is not used with the Tracking domain change. See SDK-2118 - (NSString *)branchAPIURL { @synchronized (self) { if (!_branchAPIURL) { - _branchAPIURL = [self readStringFromDefaults:BRANCH_PREFS_KEY_API_URL]; + _branchAPIURL = [self readStringFromDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL]; } // return the default URL in the event there's nothing in storage if (_branchAPIURL == nil || [_branchAPIURL isEqualToString:@""]) { _branchAPIURL = [BNC_API_URL copy]; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_API_URL value:_branchAPIURL]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL]; } return _branchAPIURL; diff --git a/BranchSDK/BNCServerAPI.m b/BranchSDK/BNCServerAPI.m index 2e9bc5c2a..6c7900911 100644 --- a/BranchSDK/BNCServerAPI.m +++ b/BranchSDK/BNCServerAPI.m @@ -9,6 +9,7 @@ #import "BNCSystemObserver.h" #import "BNCConfig.h" #import "BranchConstants.h" +#import "BNCPreferenceHelper.h" @implementation BNCServerAPI @@ -88,6 +89,12 @@ - (NSString *)getBaseURLForLinkingEndpoints { } - (NSString *)getBaseURL { + //Check if user has set a custom API base URL + NSString *url = [[BNCPreferenceHelper sharedInstance] branchAPIURL]; + if (url && ![url isEqualToString:BNC_API_URL]) { + return url; + } + if (self.automaticallyEnableTrackingDomain) { self.useTrackingDomain = [self optedIntoIDFA]; } diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index d4ab71e10..f3701460d 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -575,6 +575,12 @@ extern NSString * __nonnull const BNCSpotlightFeature; */ - (void)useEUEndpoints; +/** +Sets a custom base URL for all calls to the Branch API. +@param url Base URL that the Branch API will use. +*/ +- (void)setAPIUrl:(NSString *)url; + /** setDebug is deprecated and all functionality has been disabled. diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index da80d47ee..1d2254a75 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -426,6 +426,10 @@ - (void)useEUEndpoints { [BNCServerAPI sharedInstance].useEUServers = YES; } +- (void)setAPIUrl:(NSString *)url { + [[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url]; +} + - (void)setDebug { NSLog(@"Branch setDebug is deprecated and all functionality has been disabled. " "If you wish to enable logging, please invoke enableLogging. " diff --git a/BranchSDK/BranchPluginSupport.m b/BranchSDK/BranchPluginSupport.m index ca07797ed..e577337b3 100644 --- a/BranchSDK/BranchPluginSupport.m +++ b/BranchSDK/BranchPluginSupport.m @@ -54,7 +54,6 @@ + (BranchPluginSupport *)instance { #pragma mark - Server URL methods -// With the change to support Apple's tracking domain feature, this API no longer works. See SDK-2118 // Overrides base API URL + (void)setAPIUrl:(NSString *)url { [[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url]; From 24813678eeb7b0ee4457e4c53d325ed20ee23d43 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Tue, 13 Feb 2024 14:28:48 -0800 Subject: [PATCH 07/16] Removed method from BranchPluginSupport --- BranchSDK/BranchPluginSupport.h | 6 ------ BranchSDK/BranchPluginSupport.m | 5 ----- 2 files changed, 11 deletions(-) diff --git a/BranchSDK/BranchPluginSupport.h b/BranchSDK/BranchPluginSupport.h index d2f4cfe20..e344dcc8b 100644 --- a/BranchSDK/BranchPluginSupport.h +++ b/BranchSDK/BranchPluginSupport.h @@ -14,12 +14,6 @@ NS_ASSUME_NONNULL_BEGIN + (BranchPluginSupport *)instance; -/** -Sets a custom base URL for all calls to the Branch API. -@param url Base URL that the Branch API will use. -*/ -+ (void)setAPIUrl:(NSString *)url; - /** Sets a custom CDN base URL. @param url Base URL for CDN endpoints. diff --git a/BranchSDK/BranchPluginSupport.m b/BranchSDK/BranchPluginSupport.m index e577337b3..3cf49247b 100644 --- a/BranchSDK/BranchPluginSupport.m +++ b/BranchSDK/BranchPluginSupport.m @@ -54,11 +54,6 @@ + (BranchPluginSupport *)instance { #pragma mark - Server URL methods -// Overrides base API URL -+ (void)setAPIUrl:(NSString *)url { - [[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url]; -} - // Overrides base CDN URL + (void)setCDNBaseUrl:(NSString *)url { [[BNCPreferenceHelper sharedInstance] setPatternListURL:url]; From 9a0722e8df95e73d45e7f4ba590dc19f5f1762eb Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Tue, 13 Feb 2024 17:32:24 -0800 Subject: [PATCH 08/16] Updated to no longer save custom URL --- .../BNCPreferenceHelperTests.m | 28 ------------------ Branch-TestBed/Branch-TestBed/AppDelegate.m | 2 +- BranchSDK/BNCPreferenceHelper.h | 2 -- BranchSDK/BNCPreferenceHelper.m | 29 ------------------- BranchSDK/BNCServerAPI.h | 2 ++ BranchSDK/BNCServerAPI.m | 10 +++++-- BranchSDK/Branch.h | 2 +- BranchSDK/Branch.m | 8 +++-- 8 files changed, 17 insertions(+), 66 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m index 249fbe2de..5269501b3 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m @@ -199,34 +199,6 @@ - (void)testURLSkipList { XCTAssert([filterDesc isEqualToString:valueDesc]); } -- (void)testSetAPIURL_Example { - - NSString *url = @"https://www.example.com/"; - [self.prefHelper setBranchAPIURL:url] ; - - NSString *urlStored = self.prefHelper.branchAPIURL ; - XCTAssert([url isEqualToString:urlStored]); -} - -- (void)testSetAPIURL_InvalidHttp { - - NSString *url = @"Invalid://www.example.com/"; - [self.prefHelper setBranchAPIURL:url] ; - - NSString *urlStored = self.prefHelper.branchAPIURL ; - XCTAssert(![url isEqualToString:urlStored]); - XCTAssert([urlStored isEqualToString:BNC_API_URL]); -} - -- (void)testSetAPIURL_InvalidEmpty { - - [self.prefHelper setBranchAPIURL:@""] ; - - NSString *urlStored = self.prefHelper.branchAPIURL ; - XCTAssert(![urlStored isEqualToString:@""]); - XCTAssert([urlStored isEqualToString:BNC_API_URL]); -} - - (void)testSetCDNBaseURL_Example { NSString *url = @"https://www.example.com/"; diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index d59683f7d..d02c3a6cd 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -36,7 +36,7 @@ - (BOOL)application:(UIApplication *)application Branch *branch = [Branch getInstance]; // Change the Branch base API URL - //[branch setAPIUrl:@"https://api3.branch.io"]; + //[Branch setAPIUrl:@"https://api3.branch.io"]; // test pre init support //[self testDispatchToIsolationQueue:branch] diff --git a/BranchSDK/BNCPreferenceHelper.h b/BranchSDK/BNCPreferenceHelper.h index d7f56047b..336012609 100644 --- a/BranchSDK/BNCPreferenceHelper.h +++ b/BranchSDK/BNCPreferenceHelper.h @@ -51,7 +51,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); @property (copy, nonatomic) NSString *lastSystemBuildVersion; @property (copy, nonatomic) NSString *browserUserAgentString; @property (copy, nonatomic) NSString *referringURL; -@property (copy, nonatomic) NSString *branchAPIURL; @property (assign, nonatomic) BOOL limitFacebookTracking; @property (strong, nonatomic) NSDate *previousAppBuildDate; @property (assign, nonatomic, readwrite) BOOL disableAdNetworkCallouts; @@ -77,7 +76,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); + (BNCPreferenceHelper *)sharedInstance; -- (void)setBranchAPIURL:(NSString *)url; - (void)setPatternListURL:(NSString *)url; - (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value; diff --git a/BranchSDK/BNCPreferenceHelper.m b/BranchSDK/BNCPreferenceHelper.m index dfb9e27cd..486df900a 100644 --- a/BranchSDK/BNCPreferenceHelper.m +++ b/BranchSDK/BNCPreferenceHelper.m @@ -26,7 +26,6 @@ static NSString * const BRANCH_PREFS_KEY_LAST_RUN_BRANCH_KEY = @"bnc_last_run_branch_key"; static NSString * const BRANCH_PREFS_KEY_LAST_STRONG_MATCH_DATE = @"bnc_strong_match_created_date"; -static NSString * const BRANCH_PREFS_KEY_CUSTOM_API_URL = @"bnc_custom_api_url"; static NSString * const BRANCH_PREFS_KEY_PATTERN_LIST_URL = @"bnc_pattern_list_url"; static NSString * const BRANCH_PREFS_KEY_RANDOMIZED_DEVICE_TOKEN = @"bnc_randomized_device_token"; @@ -68,7 +67,6 @@ @interface BNCPreferenceHelper () { NSOperationQueue *_persistPrefsQueue; NSString *_lastSystemBuildVersion; NSString *_browserUserAgentString; - NSString *_branchAPIURL; NSString *_referringURL; } @@ -156,33 +154,6 @@ - (void) dealloc { #pragma mark - API methods -- (void)setBranchAPIURL:(NSString *)url { - if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ - @synchronized (self) { - _branchAPIURL = [url copy]; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL]; - } - } else { - BNCLogWarning(@"Ignoring invalid custom API URL"); - } -} - -- (NSString *)branchAPIURL { - @synchronized (self) { - if (!_branchAPIURL) { - _branchAPIURL = [self readStringFromDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL]; - } - - // return the default URL in the event there's nothing in storage - if (_branchAPIURL == nil || [_branchAPIURL isEqualToString:@""]) { - _branchAPIURL = [BNC_API_URL copy]; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_CUSTOM_API_URL value:_branchAPIURL]; - } - - return _branchAPIURL; - } -} - - (void)setPatternListURL:(NSString *)url { if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ @synchronized (self) { diff --git a/BranchSDK/BNCServerAPI.h b/BranchSDK/BNCServerAPI.h index 6fc218e65..c44c80577 100644 --- a/BranchSDK/BNCServerAPI.h +++ b/BranchSDK/BNCServerAPI.h @@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN // Used to enable unit tests without regard for ATT authorization status @property (nonatomic, assign, readwrite) BOOL automaticallyEnableTrackingDomain; +@property (nonatomic, copy, readwrite, nullable) NSString *customAPIURL; + @end NS_ASSUME_NONNULL_END diff --git a/BranchSDK/BNCServerAPI.m b/BranchSDK/BNCServerAPI.m index 6c7900911..7d7e33768 100644 --- a/BranchSDK/BNCServerAPI.m +++ b/BranchSDK/BNCServerAPI.m @@ -30,6 +30,7 @@ - (instancetype)init { self.useTrackingDomain = NO; self.useEUServers = NO; self.automaticallyEnableTrackingDomain = YES; + self.customAPIURL = NULL; } return self; } @@ -78,6 +79,10 @@ - (BOOL)optedIntoIDFA { // Linking endpoints are not used for Ads tracking - (NSString *)getBaseURLForLinkingEndpoints { + if (self.customAPIURL) { + return self.customAPIURL; + } + NSString * urlString; if (self.useEUServers){ urlString = BNC_EU_API_URL; @@ -90,9 +95,8 @@ - (NSString *)getBaseURLForLinkingEndpoints { - (NSString *)getBaseURL { //Check if user has set a custom API base URL - NSString *url = [[BNCPreferenceHelper sharedInstance] branchAPIURL]; - if (url && ![url isEqualToString:BNC_API_URL]) { - return url; + if (self.customAPIURL) { + return self.customAPIURL; } if (self.automaticallyEnableTrackingDomain) { diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index f3701460d..134877928 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -579,7 +579,7 @@ extern NSString * __nonnull const BNCSpotlightFeature; Sets a custom base URL for all calls to the Branch API. @param url Base URL that the Branch API will use. */ -- (void)setAPIUrl:(NSString *)url; ++ (void)setAPIUrl:(NSString *)url; /** setDebug is deprecated and all functionality has been disabled. diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index 1d2254a75..feece0a22 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -426,8 +426,12 @@ - (void)useEUEndpoints { [BNCServerAPI sharedInstance].useEUServers = YES; } -- (void)setAPIUrl:(NSString *)url { - [[BNCPreferenceHelper sharedInstance] setBranchAPIURL:url]; ++ (void)setAPIUrl:(NSString *)url { + if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ + [BNCServerAPI sharedInstance].customAPIURL = url; + } else { + BNCLogWarning(@"Ignoring invalid custom API URL"); + } } - (void)setDebug { From 696a513e84ca94dbf85bcdba548112d6ce0884a6 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 14 Feb 2024 14:43:09 -0800 Subject: [PATCH 09/16] Updated callback --- .../Branch-SDK-Tests/BranchLoggerTests.m | 2 ++ Branch-TestBed/Branch-TestBed/AppDelegate.m | 17 ++++++++--------- BranchSDK/Branch.h | 1 + BranchSDK/Branch.m | 7 +++++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m index 38d4f1dfa..0a9539f61 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m @@ -30,6 +30,8 @@ - (void)testLogLevelThresholdBlocksLowerLevels { logger.logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { if ([message isEqualToString:@"[BranchSDK][Debug][BranchLoggerTests testLogLevelThresholdBlocksLowerLevels] This message should trigger the log callback."] && logLevel >= BranchLogLevelDebug) { [expectation fulfill]; + } else if (logLevel == BranchLogLevelVerbose) { + XCTFail(); } }; diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index 3aeeed7b5..34c246de2 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -35,15 +35,14 @@ - (BOOL)application:(UIApplication *)application // test pre init support //[self testDispatchToIsolationQueue:branch] - [branch enableLoggingAtLevel:BranchLogLevelVerbose]; -// [BranchLogger shared].logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { -// // Handle the log message and error here. For example, printing to the console: -// if (error) { -// NSLog(@"[BranchLog] Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription); -// } else { -// NSLog(@"[BranchLog] Level: %lu, Message: %@", (unsigned long)logLevel, message); -// } -// }; + [branch enableLoggingAtLevel:BranchLogLevelVerbose withCallback:^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { + // Handle the log message and error here. For example, printing to the console: + if (error) { + NSLog(@"[BranchLog] Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription); + } else { + NSLog(@"[BranchLog] Level: %lu, Message: %@", (unsigned long)logLevel, message); + } + }]; // Comment out in production. Un-comment to test your Branch SDK Integration: //[branch validateSDKIntegration]; diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index 15a2b6d69..dd6beea97 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -568,6 +568,7 @@ extern NSString * __nonnull const BNCSpotlightFeature; */ - (void)enableLogging; - (void)enableLoggingAtLevel:(BranchLogLevel)logLevel; +- (void)enableLoggingAtLevel:(BranchLogLevel)logLevel withCallback:(nullable BranchLogCallback)callback; /** Send requests to EU endpoints. diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index d93325fc6..4d7918f1d 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -427,6 +427,13 @@ - (void)enableLoggingAtLevel:(BranchLogLevel)logLevel { logger.logLevelThreshold = logLevel; } +- (void)enableLoggingAtLevel:(BranchLogLevel)logLevel withCallback:(nullable BranchLogCallback)callback { + BranchLogger *logger = [BranchLogger shared]; + logger.loggingEnabled = YES; + logger.logLevelThreshold = logLevel; + logger.logCallback = callback; +} + - (void)useEUEndpoints { [BNCServerAPI sharedInstance].useEUServers = YES; } From fcd4194cb77e1a30929212da1f3a9376c16f9ba3 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 14 Feb 2024 14:46:34 -0800 Subject: [PATCH 10/16] Removed one method --- Branch-TestBed/Branch-TestBed/AppDelegate.m | 1 - BranchSDK/Branch.h | 1 - BranchSDK/Branch.m | 6 +----- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Branch-TestBed/Branch-TestBed/AppDelegate.m b/Branch-TestBed/Branch-TestBed/AppDelegate.m index 34c246de2..aedcf2ea9 100644 --- a/Branch-TestBed/Branch-TestBed/AppDelegate.m +++ b/Branch-TestBed/Branch-TestBed/AppDelegate.m @@ -34,7 +34,6 @@ - (BOOL)application:(UIApplication *)application // test pre init support //[self testDispatchToIsolationQueue:branch] - [branch enableLoggingAtLevel:BranchLogLevelVerbose withCallback:^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) { // Handle the log message and error here. For example, printing to the console: if (error) { diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index dd6beea97..55c425725 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -567,7 +567,6 @@ extern NSString * __nonnull const BNCSpotlightFeature; Enable debug messages to os_log. */ - (void)enableLogging; -- (void)enableLoggingAtLevel:(BranchLogLevel)logLevel; - (void)enableLoggingAtLevel:(BranchLogLevel)logLevel withCallback:(nullable BranchLogCallback)callback; /** diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index 4d7918f1d..0f4a7649a 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -418,13 +418,9 @@ + (BOOL)branchKeyIsSet { } - (void)enableLogging { - [self enableLoggingAtLevel:BranchLogLevelDebug]; -} - -- (void)enableLoggingAtLevel:(BranchLogLevel)logLevel { BranchLogger *logger = [BranchLogger shared]; logger.loggingEnabled = YES; - logger.logLevelThreshold = logLevel; + logger.logLevelThreshold = BranchLogLevelDebug; } - (void)enableLoggingAtLevel:(BranchLogLevel)logLevel withCallback:(nullable BranchLogCallback)callback { From 8eb3280706c6eeba6fd907d3a5169ca12c1dbc66 Mon Sep 17 00:00:00 2001 From: ndixit-branch <93544270+NidhiDixit09@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:11:52 -0800 Subject: [PATCH 11/16] (WIP) - SDK 2223 DMA Consent Params Implementation (#1345) SDK-2223 Added API for setting DMA Compliance Params on Server Requests. --- .../Branch-SDK-Tests/BranchClassTests.m | 11 ++++ BranchSDK/BNCPreferenceHelper.h | 5 ++ BranchSDK/BNCPreferenceHelper.m | 63 ++++++++++++++++++- BranchSDK/BNCRequestFactory.m | 20 ++++++ BranchSDK/Branch.h | 10 +++ BranchSDK/Branch.m | 6 ++ BranchSDK/BranchConstants.h | 4 ++ BranchSDK/BranchConstants.m | 5 ++ 8 files changed, 123 insertions(+), 1 deletion(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m index e695e5afb..f66ed3e53 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m @@ -220,4 +220,15 @@ - (void)testGetLongURLWithParamsAndChannelAndTagsAndFeatureAndStageAndAlias { XCTAssertEqualObjects(generatedURL, expectedURL, @"URL should match the expected format"); } +- (void)testSetDMAParamsForEEA { + + XCTAssertFalse([[BNCPreferenceHelper sharedInstance] eeaRegionInitialized]); + [Branch setDMAParamsForEEA:FALSE AdPersonalizationConsent:TRUE AdUserDataUsageConsent:TRUE]; + XCTAssertTrue([[BNCPreferenceHelper sharedInstance] eeaRegionInitialized]); + XCTAssertFalse([BNCPreferenceHelper sharedInstance].eeaRegion); + XCTAssertTrue([BNCPreferenceHelper sharedInstance].adPersonalizationConsent); + XCTAssertTrue([BNCPreferenceHelper sharedInstance].adUserDataUsageConsent); + +} + @end diff --git a/BranchSDK/BNCPreferenceHelper.h b/BranchSDK/BNCPreferenceHelper.h index d7f56047b..bc53c3e26 100644 --- a/BranchSDK/BNCPreferenceHelper.h +++ b/BranchSDK/BNCPreferenceHelper.h @@ -73,6 +73,10 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); @property (strong, nonatomic) NSDate *firstAppLaunchTime; @property (assign, nonatomic) BOOL invokeRegisterApp; +@property (assign, nonatomic) BOOL eeaRegion; +@property (assign, nonatomic) BOOL adPersonalizationConsent; +@property (assign, nonatomic) BOOL adUserDataUsageConsent; + - (void) clearTrackingInformation; + (BNCPreferenceHelper *)sharedInstance; @@ -97,5 +101,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); - (NSMutableString*) sanitizedMutableBaseURL:(NSString*)baseUrl; - (void) synchronize; // Flushes preference queue to persistence. + (void) clearAll; +- (BOOL) eeaRegionInitialized; @end diff --git a/BranchSDK/BNCPreferenceHelper.m b/BranchSDK/BNCPreferenceHelper.m index fb7a3ca58..ab9e2bd74 100644 --- a/BranchSDK/BNCPreferenceHelper.m +++ b/BranchSDK/BNCPreferenceHelper.m @@ -61,6 +61,10 @@ static NSString * const BRANCH_PREFS_KEY_LOG_IAP_AS_EVENTS = @"bnc_log_iap_as_events"; +static NSString * const BRANCH_PREFS_KEY_DMA_EEA = @"bnc_dma_eea"; +static NSString * const BRANCH_PREFS_KEY_DMA_AD_PERSONALIZATION = @"bnc_dma_ad_personalization"; +static NSString * const BRANCH_PREFS_KEY_DMA_AD_USER_DATA = @"bnc_dma_ad_user_data"; + NSURL* /* _Nonnull */ BNCURLForBranchDirectory_Unthreaded(void); @@ -114,7 +118,10 @@ @implementation BNCPreferenceHelper highestConversionValueSent = _highestConversionValueSent, referringURLQueryParameters = _referringURLQueryParameters, anonID = _anonID, - patternListURL = _patternListURL; + patternListURL = _patternListURL, + eeaRegion = _eeaRegion, + adPersonalizationConsent = _adPersonalizationConsent, + adUserDataUsageConsent = _adUserDataUsageConsent; + (BNCPreferenceHelper *)sharedInstance { static BNCPreferenceHelper *preferenceHelper; @@ -791,6 +798,60 @@ - (void) setInvokeRegisterApp:(BOOL)invoke { } } +- (BOOL) eeaRegionInitialized { + @synchronized(self) { + if([self readObjectFromDefaults:BRANCH_PREFS_KEY_DMA_EEA]) + return YES; + return NO; + } +} + +- (BOOL) eeaRegion { + @synchronized(self) { + NSNumber *b = (id) [self readObjectFromDefaults:BRANCH_PREFS_KEY_DMA_EEA]; + if ([b isKindOfClass:NSNumber.class]) return [b boolValue]; + return NO; + } +} + +- (void) setEeaRegion:(BOOL)isEEARegion { + @synchronized(self) { + NSNumber *b = [NSNumber numberWithBool:isEEARegion]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_DMA_EEA value:b]; + } +} + +- (BOOL) adPersonalizationConsent { + @synchronized(self) { + NSNumber *b = (id) [self readObjectFromDefaults:BRANCH_PREFS_KEY_DMA_AD_PERSONALIZATION]; + if ([b isKindOfClass:NSNumber.class]) return [b boolValue]; + return NO; + } +} + +- (void) setAdPersonalizationConsent:(BOOL)hasConsent { + @synchronized(self) { + NSNumber *b = [NSNumber numberWithBool:hasConsent]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_DMA_AD_PERSONALIZATION value:b]; + } +} + +- (BOOL) adUserDataUsageConsent { + @synchronized(self) { + NSNumber *b = (id) [self readObjectFromDefaults:BRANCH_PREFS_KEY_DMA_AD_USER_DATA]; + if ([b isKindOfClass:NSNumber.class]) return [b boolValue]; + return NO; + } +} + +- (void) setAdUserDataUsageConsent:(BOOL)hasConsent { + @synchronized(self) { + NSNumber *b = [NSNumber numberWithBool:hasConsent]; + [self writeObjectToDefaults:BRANCH_PREFS_KEY_DMA_AD_USER_DATA value:b]; + } +} + + - (void) clearTrackingInformation { @synchronized(self) { /* diff --git a/BranchSDK/BNCRequestFactory.m b/BranchSDK/BNCRequestFactory.m index 7386e9641..c9ca42c18 100644 --- a/BranchSDK/BNCRequestFactory.m +++ b/BranchSDK/BNCRequestFactory.m @@ -110,6 +110,9 @@ - (NSDictionary *)dataForInstall { // TODO: refactor to simply request values for install [self addReferringURLsToJSON:json forEndpoint:@"/v1/install"]; + // Add DMA Compliance Params for Google + [self addDMAConsentParamsToJSON:json]; + return json; } @@ -150,6 +153,9 @@ - (NSDictionary *)dataForOpen { // TODO: refactor to simply request values for open [self addReferringURLsToJSON:json forEndpoint:@"/v1/open"]; + // Add DMA Compliance Params for Google + [self addDMAConsentParamsToJSON:json]; + return json; } @@ -181,6 +187,7 @@ - (NSDictionary *)dataForEventWithEventDictionary:(NSMutableDictionary *)diction // TODO: refactor to simply request values for event [self addReferringURLsToJSON:json forEndpoint:@"/v2/event"]; + return json; } @@ -319,6 +326,16 @@ - (void)addPartnerParametersToJSON:(NSMutableDictionary *)json { } } +- (void)addDMAConsentParamsToJSON:(NSMutableDictionary *)json { + + if([self.preferenceHelper eeaRegionInitialized]){ + [self safeSetValue:@([self.preferenceHelper eeaRegion]) forKey:BRANCH_REQUEST_KEY_DMA_EEA onDict:json]; + [self safeSetValue:@([self.preferenceHelper adPersonalizationConsent]) forKey:BRANCH_REQUEST_KEY_DMA_AD_PEROSALIZATION onDict:json]; + [self safeSetValue:@([self.preferenceHelper adUserDataUsageConsent]) forKey:BRANCH_REQUEST_KEY_DMA_AD_USER_DATA onDict:json]; + } +} + + - (void)addLocalURLToInstallJSON:(NSMutableDictionary *)json { if ([BNCPasteboard sharedInstance].checkOnInstall) { NSURL *pasteboardURL = nil; @@ -523,6 +540,9 @@ - (NSDictionary *)v2dictionary { dictionary[@"sdk"] = @"ios"; } + // Add DMA Compliance Params for Google + [self addDMAConsentParamsToJSON:dictionary]; + return dictionary; } diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index d4ab71e10..0a1057684 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -834,6 +834,16 @@ extern NSString * __nonnull const BNCSpotlightFeature; */ + (void) setReferrerGbraidValidityWindow:(NSTimeInterval) validityWindow; +/* + + Sets the value of parameters required by Google Conversion APIs for DMA Compliance in EEA region. + + @param eeaRegion -(BOOL) If European regulations, including the DMA, apply to this user and conversion. + @param adPersonalizationConsent - (BOOL) If End user has granted/denied ads personalization consent. + @param adUserDataUsageConsent - (BOOL) If User has granted/denied consent for 3P transmission of user level data for ads + */ ++ (void) setDMAParamsForEEA:(BOOL) eeaRegion AdPersonalizationConsent:(BOOL) adPersonalizationConsent AdUserDataUsageConsent:(BOOL) adUserDataUsageConsent; + #pragma mark - Session Item methods ///-------------------- diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index da80d47ee..c4bdd5b04 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -540,6 +540,12 @@ + (void)setReferrerGbraidValidityWindow:(NSTimeInterval)validityWindow{ } } ++ (void) setDMAParamsForEEA:(BOOL)eeaRegion AdPersonalizationConsent:(BOOL)adPersonalizationConsent AdUserDataUsageConsent:(BOOL)adUserDataUsageConsent{ + [BNCPreferenceHelper sharedInstance].eeaRegion = eeaRegion; + [BNCPreferenceHelper sharedInstance].adPersonalizationConsent = adPersonalizationConsent; + [BNCPreferenceHelper sharedInstance].adUserDataUsageConsent = adUserDataUsageConsent; +} + #pragma mark - InitSession Permutation methods - (void)initSessionWithLaunchOptions:(NSDictionary *)options { diff --git a/BranchSDK/BranchConstants.h b/BranchSDK/BranchConstants.h index 013622446..da64586c4 100644 --- a/BranchSDK/BranchConstants.h +++ b/BranchSDK/BranchConstants.h @@ -163,3 +163,7 @@ extern NSString * const BRANCH_REQUEST_KEY_SKAN_POSTBACK_INDEX; extern NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_0; extern NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_1; extern NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_2; + +extern NSString * const BRANCH_REQUEST_KEY_DMA_EEA; +extern NSString * const BRANCH_REQUEST_KEY_DMA_AD_PEROSALIZATION; +extern NSString * const BRANCH_REQUEST_KEY_DMA_AD_USER_DATA; diff --git a/BranchSDK/BranchConstants.m b/BranchSDK/BranchConstants.m index f4d12989d..96749379b 100644 --- a/BranchSDK/BranchConstants.m +++ b/BranchSDK/BranchConstants.m @@ -161,3 +161,8 @@ NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_0 = @"postback-sequence-index-0"; NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_1 = @"postback-sequence-index-1"; NSString * const BRANCH_REQUEST_KEY_VALUE_POSTBACK_SEQUENCE_INDEX_2 = @"postback-sequence-index-2"; + +NSString * const BRANCH_REQUEST_KEY_DMA_EEA = @"dma_eea"; +NSString * const BRANCH_REQUEST_KEY_DMA_AD_PEROSALIZATION = @"dma_ad_personalization"; +NSString * const BRANCH_REQUEST_KEY_DMA_AD_USER_DATA = @"dma_ad_user_data"; + From 1c806b8ee17ab83314adc83c25726045743a9c25 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 14 Feb 2024 16:55:02 -0800 Subject: [PATCH 12/16] Added files to framework --- BranchSDK.xcodeproj/project.pbxproj | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/BranchSDK.xcodeproj/project.pbxproj b/BranchSDK.xcodeproj/project.pbxproj index 796471c83..5e29a8450 100644 --- a/BranchSDK.xcodeproj/project.pbxproj +++ b/BranchSDK.xcodeproj/project.pbxproj @@ -117,7 +117,6 @@ 5F22110C2894A34000C5B190 /* BNCCrashlyticsWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F22106E2894A33F00C5B190 /* BNCCrashlyticsWrapper.h */; }; 5F22110E2894A34000C5B190 /* BranchContentDiscoverer.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210702894A33F00C5B190 /* BranchContentDiscoverer.h */; }; 5F22110F2894A34000C5B190 /* BranchContentDiscoverer.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210712894A33F00C5B190 /* BranchContentDiscoverer.m */; }; - 5F2211102894A34000C5B190 /* BNCLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210722894A33F00C5B190 /* BNCLog.m */; }; 5F2211112894A34000C5B190 /* BNCContentDiscoveryManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210732894A33F00C5B190 /* BNCContentDiscoveryManager.h */; }; 5F2211122894A34000C5B190 /* BNCInitSessionResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210742894A33F00C5B190 /* BNCInitSessionResponse.m */; }; 5F2211142894A34000C5B190 /* BranchConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210762894A33F00C5B190 /* BranchConstants.h */; }; @@ -170,7 +169,6 @@ 5F22114C2894A34000C5B190 /* NSError+Branch.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210AE2894A34000C5B190 /* NSError+Branch.m */; }; 5F22114D2894A34000C5B190 /* BNCServerRequestQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210AF2894A34000C5B190 /* BNCServerRequestQueue.m */; }; 5F22114E2894A34000C5B190 /* BranchLastAttributedTouchData.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210B02894A34000C5B190 /* BranchLastAttributedTouchData.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5F22114F2894A34000C5B190 /* BNCLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210B12894A34000C5B190 /* BNCLog.h */; }; 5F2211502894A34000C5B190 /* BNCEncodingUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210B22894A34000C5B190 /* BNCEncodingUtils.h */; }; 5F2211512894A34000C5B190 /* BNCNetworkService.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210B32894A34000C5B190 /* BNCNetworkService.m */; }; 5F2211522894A34000C5B190 /* BNCPartnerParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210B42894A34000C5B190 /* BNCPartnerParameters.m */; }; @@ -222,7 +220,6 @@ 5F7903A828B59146003144CD /* BNCKeyChain.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210B52894A34000C5B190 /* BNCKeyChain.h */; }; 5F7903A928B59146003144CD /* BNCLinkCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210552894A33F00C5B190 /* BNCLinkCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5F7903AA28B59146003144CD /* BNCLinkData.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210532894A33F00C5B190 /* BNCLinkData.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5F7903AC28B59146003144CD /* BNCLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210B12894A34000C5B190 /* BNCLog.h */; }; 5F7903AD28B59146003144CD /* BNCNetworkInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210AA2894A34000C5B190 /* BNCNetworkInterface.h */; }; 5F7903AE28B59146003144CD /* BNCNetworkService.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F22104D2894A33F00C5B190 /* BNCNetworkService.h */; }; 5F7903AF28B59146003144CD /* BNCNetworkServiceProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210592894A33F00C5B190 /* BNCNetworkServiceProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -277,7 +274,6 @@ 5F7903F728B5C93E003144CD /* BNCKeyChain.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210932894A34000C5B190 /* BNCKeyChain.m */; }; 5F7903F828B5C93E003144CD /* BNCLinkCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F22104E2894A33F00C5B190 /* BNCLinkCache.m */; }; 5F7903F928B5C93E003144CD /* BNCLinkData.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210A42894A34000C5B190 /* BNCLinkData.m */; }; - 5F7903FB28B5C93E003144CD /* BNCLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210722894A33F00C5B190 /* BNCLog.m */; }; 5F7903FC28B5C93E003144CD /* BNCNetworkInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210BD2894A34000C5B190 /* BNCNetworkInterface.m */; }; 5F7903FD28B5C93E003144CD /* BNCNetworkService.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210B32894A34000C5B190 /* BNCNetworkService.m */; }; 5F7903FE28B5C93E003144CD /* BNCPartnerParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210B42894A34000C5B190 /* BNCPartnerParameters.m */; }; @@ -336,7 +332,6 @@ 5FF9DE1F28EE78A700D62DE1 /* BNCKeyChain.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210932894A34000C5B190 /* BNCKeyChain.m */; }; 5FF9DE2128EE78A700D62DE1 /* BNCLinkCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F22104E2894A33F00C5B190 /* BNCLinkCache.m */; }; 5FF9DE2328EE78A700D62DE1 /* BNCLinkData.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210A42894A34000C5B190 /* BNCLinkData.m */; }; - 5FF9DE2728EE78A800D62DE1 /* BNCLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210722894A33F00C5B190 /* BNCLog.m */; }; 5FF9DE2928EE78A800D62DE1 /* BNCNetworkInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210BD2894A34000C5B190 /* BNCNetworkInterface.m */; }; 5FF9DE2B28EE78A800D62DE1 /* BNCNetworkService.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210B32894A34000C5B190 /* BNCNetworkService.m */; }; 5FF9DE2E28EE78A800D62DE1 /* BNCPartnerParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F2210B42894A34000C5B190 /* BNCPartnerParameters.m */; }; @@ -400,7 +395,6 @@ 5FF9DEAA28EE797300D62DE1 /* BNCKeyChain.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210B52894A34000C5B190 /* BNCKeyChain.h */; }; 5FF9DEAB28EE797300D62DE1 /* BNCLinkCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210552894A33F00C5B190 /* BNCLinkCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5FF9DEAC28EE797300D62DE1 /* BNCLinkData.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210532894A33F00C5B190 /* BNCLinkData.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5FF9DEAE28EE797300D62DE1 /* BNCLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210B12894A34000C5B190 /* BNCLog.h */; }; 5FF9DEAF28EE797300D62DE1 /* BNCNetworkInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210AA2894A34000C5B190 /* BNCNetworkInterface.h */; }; 5FF9DEB028EE797300D62DE1 /* BNCNetworkService.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F22104D2894A33F00C5B190 /* BNCNetworkService.h */; }; 5FF9DEB128EE797300D62DE1 /* BNCNetworkServiceProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210592894A33F00C5B190 /* BNCNetworkServiceProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -449,6 +443,12 @@ 5FF9DEE528EE797400D62DE1 /* NSString+Branch.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210582894A33F00C5B190 /* NSString+Branch.h */; }; 5FF9DEE628EE797400D62DE1 /* UIViewController+Branch.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F22107B2894A33F00C5B190 /* UIViewController+Branch.h */; }; 5FF9DEE728EE7A7F00D62DE1 /* BranchSDK.h in Headers */ = {isa = PBXBuildFile; fileRef = 5FF2AFDF28E7C22100393216 /* BranchSDK.h */; settings = {ATTRIBUTES = (Public, ); }; }; + C16B97A92B7D980F00FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B97A72B7D980F00FB0631 /* BranchLogger.h */; }; + C16B97AA2B7D980F00FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B97A72B7D980F00FB0631 /* BranchLogger.h */; }; + C16B97AB2B7D980F00FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B97A72B7D980F00FB0631 /* BranchLogger.h */; }; + C16B97AC2B7D980F00FB0631 /* BranchLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B97A82B7D980F00FB0631 /* BranchLogger.m */; }; + C16B97AD2B7D980F00FB0631 /* BranchLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B97A82B7D980F00FB0631 /* BranchLogger.m */; }; + C16B97AE2B7D980F00FB0631 /* BranchLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B97A82B7D980F00FB0631 /* BranchLogger.m */; }; C1B63C7D29D2380000D1136D /* BNCUrlQueryParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = C1B63C7929D2380000D1136D /* BNCUrlQueryParameter.m */; }; C1B63C7E29D2380000D1136D /* BNCReferringURLUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = C1B63C7A29D2380000D1136D /* BNCReferringURLUtility.m */; }; C1B63C7F29D2380000D1136D /* BNCUrlQueryParameter.h in Headers */ = {isa = PBXBuildFile; fileRef = C1B63C7B29D2380000D1136D /* BNCUrlQueryParameter.h */; }; @@ -588,7 +588,6 @@ 5F22106E2894A33F00C5B190 /* BNCCrashlyticsWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCCrashlyticsWrapper.h; sourceTree = ""; }; 5F2210702894A33F00C5B190 /* BranchContentDiscoverer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchContentDiscoverer.h; sourceTree = ""; }; 5F2210712894A33F00C5B190 /* BranchContentDiscoverer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchContentDiscoverer.m; sourceTree = ""; }; - 5F2210722894A33F00C5B190 /* BNCLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCLog.m; sourceTree = ""; }; 5F2210732894A33F00C5B190 /* BNCContentDiscoveryManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCContentDiscoveryManager.h; sourceTree = ""; }; 5F2210742894A33F00C5B190 /* BNCInitSessionResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCInitSessionResponse.m; sourceTree = ""; }; 5F2210762894A33F00C5B190 /* BranchConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchConstants.h; sourceTree = ""; }; @@ -641,7 +640,6 @@ 5F2210AE2894A34000C5B190 /* NSError+Branch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+Branch.m"; sourceTree = ""; }; 5F2210AF2894A34000C5B190 /* BNCServerRequestQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCServerRequestQueue.m; sourceTree = ""; }; 5F2210B02894A34000C5B190 /* BranchLastAttributedTouchData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchLastAttributedTouchData.h; sourceTree = ""; }; - 5F2210B12894A34000C5B190 /* BNCLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCLog.h; sourceTree = ""; }; 5F2210B22894A34000C5B190 /* BNCEncodingUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BNCEncodingUtils.h; sourceTree = ""; }; 5F2210B32894A34000C5B190 /* BNCNetworkService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCNetworkService.m; sourceTree = ""; }; 5F2210B42894A34000C5B190 /* BNCPartnerParameters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BNCPartnerParameters.m; sourceTree = ""; }; @@ -684,6 +682,8 @@ 5FF2AFDC28E7BF8A00393216 /* build_xcframework.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build_xcframework.sh; sourceTree = ""; }; 5FF2AFDE28E7C22100393216 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; 5FF2AFDF28E7C22100393216 /* BranchSDK.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BranchSDK.h; sourceTree = ""; }; + C16B97A72B7D980F00FB0631 /* BranchLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchLogger.h; sourceTree = ""; }; + C16B97A82B7D980F00FB0631 /* BranchLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchLogger.m; sourceTree = ""; }; C1B63C7929D2380000D1136D /* BNCUrlQueryParameter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCUrlQueryParameter.m; sourceTree = ""; }; C1B63C7A29D2380000D1136D /* BNCReferringURLUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCReferringURLUtility.m; sourceTree = ""; }; C1B63C7B29D2380000D1136D /* BNCUrlQueryParameter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCUrlQueryParameter.h; sourceTree = ""; }; @@ -813,8 +813,6 @@ 5F22104E2894A33F00C5B190 /* BNCLinkCache.m */, 5F2210532894A33F00C5B190 /* BNCLinkData.h */, 5F2210A42894A34000C5B190 /* BNCLinkData.m */, - 5F2210B12894A34000C5B190 /* BNCLog.h */, - 5F2210722894A33F00C5B190 /* BNCLog.m */, 5F2210AA2894A34000C5B190 /* BNCNetworkInterface.h */, 5F2210BD2894A34000C5B190 /* BNCNetworkInterface.m */, 5F22104D2894A33F00C5B190 /* BNCNetworkService.h */, @@ -913,6 +911,8 @@ 5F2210942894A34000C5B190 /* BranchUniversalObject.m */, 5F2210BC2894A34000C5B190 /* NSError+Branch.h */, 5F2210AE2894A34000C5B190 /* NSError+Branch.m */, + C16B97A72B7D980F00FB0631 /* BranchLogger.h */, + C16B97A82B7D980F00FB0631 /* BranchLogger.m */, 5F2210992894A34000C5B190 /* NSMutableDictionary+Branch.h */, 5F2210352894A33E00C5B190 /* NSMutableDictionary+Branch.m */, 5F2210582894A33F00C5B190 /* NSString+Branch.h */, @@ -1003,6 +1003,7 @@ 5F2211492894A34000C5B190 /* BranchDeepLinkingController.h in Headers */, 5F2211072894A34000C5B190 /* BranchDelegate.h in Headers */, 5F22111B2894A34000C5B190 /* BranchEvent.h in Headers */, + C16B97A92B7D980F00FB0631 /* BranchLogger.h in Headers */, 5F22114E2894A34000C5B190 /* BranchLastAttributedTouchData.h in Headers */, 5F2210ED2894A34000C5B190 /* BranchLinkProperties.h in Headers */, 5F2210FF2894A34000C5B190 /* BranchScene.h in Headers */, @@ -1058,7 +1059,6 @@ E761E92429E61DA000E55C98 /* BNCEventUtils.h in Headers */, 5F22111A2894A34000C5B190 /* BNCDeepLinkViewControllerInstance.h in Headers */, 5F2210D92894A34000C5B190 /* BNCAppleReceipt.h in Headers */, - 5F22114F2894A34000C5B190 /* BNCLog.h in Headers */, 5F2210D72894A34000C5B190 /* BNCJSONUtility.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1085,9 +1085,9 @@ 5FF9DEA828EE797300D62DE1 /* BNCInitSessionResponse.h in Headers */, 5FF9DEA928EE797300D62DE1 /* BNCJSONUtility.h in Headers */, 5FF9DEAA28EE797300D62DE1 /* BNCKeyChain.h in Headers */, + C16B97AA2B7D980F00FB0631 /* BranchLogger.h in Headers */, 5FF9DEAB28EE797300D62DE1 /* BNCLinkCache.h in Headers */, 5FF9DEAC28EE797300D62DE1 /* BNCLinkData.h in Headers */, - 5FF9DEAE28EE797300D62DE1 /* BNCLog.h in Headers */, 5FF9DEAF28EE797300D62DE1 /* BNCNetworkInterface.h in Headers */, 5FF9DEB028EE797300D62DE1 /* BNCNetworkService.h in Headers */, C1B63C8129D34EEF00D1136D /* BNCReferringURLUtility.h in Headers */, @@ -1187,7 +1187,6 @@ 5F7903A528B59146003144CD /* BNCFieldDefines.h in Headers */, 5F7903A728B59146003144CD /* BNCJSONUtility.h in Headers */, 5F7903A828B59146003144CD /* BNCKeyChain.h in Headers */, - 5F7903AC28B59146003144CD /* BNCLog.h in Headers */, 5F7903AD28B59146003144CD /* BNCNetworkInterface.h in Headers */, 5F7903AE28B59146003144CD /* BNCNetworkService.h in Headers */, 5F7903B028B59146003144CD /* BNCPartnerParameters.h in Headers */, @@ -1198,6 +1197,7 @@ 5F7903B928B59147003144CD /* BNCSKAdNetwork.h in Headers */, 5F7903BB28B59147003144CD /* BNCSystemObserver.h in Headers */, 5F7903BD28B59147003144CD /* BNCThreads.h in Headers */, + C16B97AB2B7D980F00FB0631 /* BranchLogger.h in Headers */, 5F7903BF28B59147003144CD /* BNCURLFilter.h in Headers */, C1BE79832A9E708900E15EDF /* BNCProductCategory.h in Headers */, 5F7903C228B59147003144CD /* Branch+Validator.h in Headers */, @@ -1535,11 +1535,11 @@ E761E92129E61DA000E55C98 /* BNCEventUtils.m in Sources */, C1B63C7D29D2380000D1136D /* BNCUrlQueryParameter.m in Sources */, C1B63C7E29D2380000D1136D /* BNCReferringURLUtility.m in Sources */, + C16B97AC2B7D980F00FB0631 /* BranchLogger.m in Sources */, 5F2211512894A34000C5B190 /* BNCNetworkService.m in Sources */, 5F22115B2894A34000C5B190 /* BNCNetworkInterface.m in Sources */, 5F2211592894A34000C5B190 /* BNCDeviceInfo.m in Sources */, 5F2210D32894A34000C5B190 /* NSMutableDictionary+Branch.m in Sources */, - 5F2211102894A34000C5B190 /* BNCLog.m in Sources */, 5F22110F2894A34000C5B190 /* BranchContentDiscoverer.m in Sources */, 5F2211542894A34000C5B190 /* BNCContentDiscoveryManager.m in Sources */, 5F2211422894A34000C5B190 /* BNCLinkData.m in Sources */, @@ -1640,6 +1640,7 @@ E761E92229E61DA000E55C98 /* BNCEventUtils.m in Sources */, C1B63C8329D34EF700D1136D /* BNCReferringURLUtility.m in Sources */, C1B63C8429D34EF700D1136D /* BNCUrlQueryParameter.m in Sources */, + C16B97AD2B7D980F00FB0631 /* BranchLogger.m in Sources */, 5FF9DDFB28EE78A700D62DE1 /* BNCAppGroupsData.m in Sources */, 5FF9DDFF28EE78A700D62DE1 /* BNCAppleReceipt.m in Sources */, 5FF9DE0328EE78A700D62DE1 /* BNCApplication.m in Sources */, @@ -1659,7 +1660,6 @@ 5FF9DE2328EE78A700D62DE1 /* BNCLinkData.m in Sources */, 5F1B240C29148CBD003BEEC7 /* BranchPasteControl.m in Sources */, C1BE79802A9E707200E15EDF /* BNCCurrency.m in Sources */, - 5FF9DE2728EE78A800D62DE1 /* BNCLog.m in Sources */, 5FF9DE2928EE78A800D62DE1 /* BNCNetworkInterface.m in Sources */, 5FF9DE2B28EE78A800D62DE1 /* BNCNetworkService.m in Sources */, 5FF9DE2E28EE78A800D62DE1 /* BNCPartnerParameters.m in Sources */, @@ -1726,7 +1726,6 @@ 5F7903F828B5C93E003144CD /* BNCLinkCache.m in Sources */, 5F7903F928B5C93E003144CD /* BNCLinkData.m in Sources */, E761E92329E61DA000E55C98 /* BNCEventUtils.m in Sources */, - 5F7903FB28B5C93E003144CD /* BNCLog.m in Sources */, 5F7903FC28B5C93E003144CD /* BNCNetworkInterface.m in Sources */, 5F7903FD28B5C93E003144CD /* BNCNetworkService.m in Sources */, 5F7903FE28B5C93E003144CD /* BNCPartnerParameters.m in Sources */, @@ -1758,6 +1757,7 @@ 5F79042228B5C93F003144CD /* BranchOpenRequest.m in Sources */, 5F79042328B5C93F003144CD /* BranchPluginSupport.m in Sources */, 5F79042428B5C93F003144CD /* BranchQRCode.m in Sources */, + C16B97AE2B7D980F00FB0631 /* BranchLogger.m in Sources */, 5F79042628B5C93F003144CD /* BranchScene.m in Sources */, 5F79042928B5C93F003144CD /* BranchShortUrlRequest.m in Sources */, 5F79042A28B5C93F003144CD /* BranchShortUrlSyncRequest.m in Sources */, From 911f3b527ecb3e0f897e391e9d94cd533dd03603 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 14 Feb 2024 17:02:32 -0800 Subject: [PATCH 13/16] Fixed files --- BranchSDK.xcodeproj/project.pbxproj | 6 +++--- Framework/BranchSDK.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/BranchSDK.xcodeproj/project.pbxproj b/BranchSDK.xcodeproj/project.pbxproj index 5e29a8450..a6b0bdbf1 100644 --- a/BranchSDK.xcodeproj/project.pbxproj +++ b/BranchSDK.xcodeproj/project.pbxproj @@ -443,9 +443,9 @@ 5FF9DEE528EE797400D62DE1 /* NSString+Branch.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2210582894A33F00C5B190 /* NSString+Branch.h */; }; 5FF9DEE628EE797400D62DE1 /* UIViewController+Branch.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F22107B2894A33F00C5B190 /* UIViewController+Branch.h */; }; 5FF9DEE728EE7A7F00D62DE1 /* BranchSDK.h in Headers */ = {isa = PBXBuildFile; fileRef = 5FF2AFDF28E7C22100393216 /* BranchSDK.h */; settings = {ATTRIBUTES = (Public, ); }; }; - C16B97A92B7D980F00FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B97A72B7D980F00FB0631 /* BranchLogger.h */; }; - C16B97AA2B7D980F00FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B97A72B7D980F00FB0631 /* BranchLogger.h */; }; - C16B97AB2B7D980F00FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B97A72B7D980F00FB0631 /* BranchLogger.h */; }; + C16B97A92B7D980F00FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B97A72B7D980F00FB0631 /* BranchLogger.h */; settings = {ATTRIBUTES = (Public, ); }; }; + C16B97AA2B7D980F00FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B97A72B7D980F00FB0631 /* BranchLogger.h */; settings = {ATTRIBUTES = (Public, ); }; }; + C16B97AB2B7D980F00FB0631 /* BranchLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = C16B97A72B7D980F00FB0631 /* BranchLogger.h */; settings = {ATTRIBUTES = (Public, ); }; }; C16B97AC2B7D980F00FB0631 /* BranchLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B97A82B7D980F00FB0631 /* BranchLogger.m */; }; C16B97AD2B7D980F00FB0631 /* BranchLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B97A82B7D980F00FB0631 /* BranchLogger.m */; }; C16B97AE2B7D980F00FB0631 /* BranchLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = C16B97A82B7D980F00FB0631 /* BranchLogger.m */; }; diff --git a/Framework/BranchSDK.h b/Framework/BranchSDK.h index bc23920bd..8a61eaf97 100644 --- a/Framework/BranchSDK.h +++ b/Framework/BranchSDK.h @@ -24,6 +24,7 @@ FOUNDATION_EXPORT const unsigned char BranchSDKVersionString[]; #import #import #import +#import #import From 19692a03ef017771cc51c888f5c7567701b6d274 Mon Sep 17 00:00:00 2001 From: nsingh-branch Date: Wed, 14 Feb 2024 17:25:35 -0800 Subject: [PATCH 14/16] Added tests and changed NULL to nil --- .../Branch-SDK-Tests/BNCAPIServerTest.m | 39 +++++++++++++++++++ BranchSDK/BNCServerAPI.m | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCAPIServerTest.m b/Branch-TestBed/Branch-SDK-Tests/BNCAPIServerTest.m index 5f70fcb68..b7df6da68 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCAPIServerTest.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCAPIServerTest.m @@ -11,6 +11,7 @@ #import "BNCSystemObserver.h" #import "BNCConfig.h" #import "BranchConstants.h" +#import "Branch.h" @interface BNCAPIServerTest : XCTestCase @@ -370,4 +371,42 @@ - (void)testValidationServiceURL_EUTracking { XCTAssertTrue([url hasPrefix:expectedUrlPrefix]); } +- (void)testDefaultAPIURL { + BNCServerAPI *serverAPI = [BNCServerAPI new]; + XCTAssertNil(serverAPI.customAPIURL); + + NSString *storedUrl = [[BNCServerAPI sharedInstance] installServiceURL]; + NSString *expectedUrl = [BNC_API_URL stringByAppendingString: @"/v1/install"]; + XCTAssertEqualObjects(storedUrl, expectedUrl); +} + +- (void)testSetAPIURL_Example { + NSString *url = @"https://www.example.com"; + [Branch setAPIUrl:url]; + + NSString *storedUrl = [[BNCServerAPI sharedInstance] installServiceURL]; + NSString *expectedUrl = [url stringByAppendingString: @"/v1/install"]; + XCTAssertEqualObjects(storedUrl, expectedUrl); + + [Branch setAPIUrl:BNC_API_URL]; +} + +- (void)testSetAPIURL_InvalidHttp { + NSString *url = @"Invalid://www.example.com"; + [Branch setAPIUrl:url]; + + NSString *storedUrl = [[BNCServerAPI sharedInstance] installServiceURL]; + NSString *expectedUrl = [BNC_API_URL stringByAppendingString: @"/v1/install"]; + XCTAssertEqualObjects(storedUrl, expectedUrl); +} + +- (void)testSetAPIURL_InvalidEmpty { + NSString *url = @""; + [Branch setAPIUrl:url]; + + NSString *storedUrl = [[BNCServerAPI sharedInstance] installServiceURL]; + NSString *expectedUrl = [BNC_API_URL stringByAppendingString: @"/v1/install"]; + XCTAssertEqualObjects(storedUrl, expectedUrl); +} + @end diff --git a/BranchSDK/BNCServerAPI.m b/BranchSDK/BNCServerAPI.m index 7d7e33768..73f8cb253 100644 --- a/BranchSDK/BNCServerAPI.m +++ b/BranchSDK/BNCServerAPI.m @@ -30,7 +30,7 @@ - (instancetype)init { self.useTrackingDomain = NO; self.useEUServers = NO; self.automaticallyEnableTrackingDomain = YES; - self.customAPIURL = NULL; + self.customAPIURL = nil; } return self; } From 9463e615c0e23c59be4705211a66b089aee960a9 Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 14 Feb 2024 19:27:24 -0800 Subject: [PATCH 15/16] Selected the wrong code to keep during merge, also updated the log message. --- BranchSDK/Branch.h | 6 ++++++ BranchSDK/Branch.m | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/BranchSDK/Branch.h b/BranchSDK/Branch.h index 2f42f99d2..1ef83a061 100644 --- a/BranchSDK/Branch.h +++ b/BranchSDK/Branch.h @@ -576,6 +576,12 @@ extern NSString * __nonnull const BNCSpotlightFeature; */ - (void)useEUEndpoints; +/** +Sets a custom base URL for all calls to the Branch API. +@param url Base URL that the Branch API will use. +*/ ++ (void)setAPIUrl:(NSString *)url; + /** @brief Use the `validateSDKIntegration` method as a debugging aid to assure that you've integrated the Branch SDK correctly. diff --git a/BranchSDK/Branch.m b/BranchSDK/Branch.m index e4068e78c..d91fb6d8f 100644 --- a/BranchSDK/Branch.m +++ b/BranchSDK/Branch.m @@ -434,6 +434,14 @@ - (void)useEUEndpoints { [BNCServerAPI sharedInstance].useEUServers = YES; } ++ (void)setAPIUrl:(NSString *)url { + if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"] ){ + [BNCServerAPI sharedInstance].customAPIURL = url; + } else { + [[BranchLogger shared] logWarning:(@"Ignoring invalid custom API URL")]; + } +} + - (void)validateSDKIntegration { [self validateSDKIntegrationCore]; } From 1c4df070a1e7679998bd4951ccd91bcb2ac30dc5 Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 14 Feb 2024 21:00:16 -0800 Subject: [PATCH 16/16] Test for EEA is failing on repeat run. --- Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m index f66ed3e53..9d337a14e 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m @@ -13,6 +13,11 @@ #import "BNCAppGroupsData.h" #import "BNCPartnerParameters.h" +@interface BNCPreferenceHelper(Test) +// Expose internal private method to clear EEA data +- (void)writeObjectToDefaults:(NSString *)key value:(NSObject *)value; +@end + @interface BranchClassTests : XCTestCase @property (nonatomic, strong) Branch *branch; @end @@ -221,14 +226,19 @@ - (void)testGetLongURLWithParamsAndChannelAndTagsAndFeatureAndStageAndAlias { } - (void)testSetDMAParamsForEEA { - XCTAssertFalse([[BNCPreferenceHelper sharedInstance] eeaRegionInitialized]); + [Branch setDMAParamsForEEA:FALSE AdPersonalizationConsent:TRUE AdUserDataUsageConsent:TRUE]; XCTAssertTrue([[BNCPreferenceHelper sharedInstance] eeaRegionInitialized]); XCTAssertFalse([BNCPreferenceHelper sharedInstance].eeaRegion); XCTAssertTrue([BNCPreferenceHelper sharedInstance].adPersonalizationConsent); XCTAssertTrue([BNCPreferenceHelper sharedInstance].adUserDataUsageConsent); + // Manually clear values after testing + // By design, this API is meant to be set once and always set. However, in a test scenario it needs to be cleared. + [[BNCPreferenceHelper sharedInstance] writeObjectToDefaults:@"bnc_dma_eea" value:nil]; + [[BNCPreferenceHelper sharedInstance] writeObjectToDefaults:@"bnc_dma_ad_personalization" value:nil]; + [[BNCPreferenceHelper sharedInstance] writeObjectToDefaults:@"bnc_dma_ad_user_data" value:nil]; } @end