Skip to content

Commit

Permalink
Release 3.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Nov 18, 2024
1 parent 93340fd commit 67b02bf
Show file tree
Hide file tree
Showing 24 changed files with 536 additions and 109 deletions.
21 changes: 21 additions & 0 deletions Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,25 @@ - (void)testSetDMAParamsForEEA {
[[BNCPreferenceHelper sharedInstance] writeObjectToDefaults:@"bnc_dma_ad_user_data" value:nil];
}

- (void)testSetConsumerProtectionAttributionLevel {
// Set to Reduced and check
Branch *branch = [Branch getInstance];
[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced];
XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelReduced);

// Set to Minimal and check
[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelMinimal];
XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelMinimal);

// Set to None and check
[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelNone];
XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelNone);

// Set to Full and check
[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelFull];
XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelFull);

}


@end
41 changes: 33 additions & 8 deletions Branch-TestBed/Branch-TestBed/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[self setBranchLogFile];

appDelegate = self;

/*
Expand All @@ -32,20 +34,28 @@ - (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]
[branch enableLoggingAtLevel:BranchLogLevelVerbose withCallback:^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) {


[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);
}

NSString *logEntry = error ? [NSString stringWithFormat:@"Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription]
: [NSString stringWithFormat:@"Level: %lu, Message: %@", (unsigned long)logLevel, message];
APPLogHookFunction([NSDate date], logLevel, logEntry);
}];


// Comment out in production. Un-comment to test your Branch SDK Integration:
//[branch validateSDKIntegration];

Expand All @@ -58,14 +68,16 @@ - (BOOL)application:(UIApplication *)application
* Required: Initialize Branch, passing a deep link handler block:
*/

[self setLogFile:@"OpenNInstall"];
//[self setLogFile:@"OpenNInstall"];

[branch setIdentity:@"Bobby Branch"];

//[[Branch getInstance] setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced];

[branch initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandlerUsingBranchUniversalObject:
^ (BranchUniversalObject * _Nullable universalObject, BranchLinkProperties * _Nullable linkProperties, NSError * _Nullable error) {

[self setLogFile:nil];
//[self setLogFile:nil];
[self handleDeepLinkObject:universalObject linkProperties:linkProperties error:error];
}];

Expand Down Expand Up @@ -134,7 +146,7 @@ - (void) handleDeepLinkObject:(BranchUniversalObject*)object
[storyboard instantiateViewControllerWithIdentifier:@"LogOutputViewController"];
[navigationController pushViewController:logOutputViewController animated:YES];
NSString *logOutput =
[NSString stringWithFormat:@"Successfully Deeplinked:\n\n%@\nSession Details:\n\n%@",
[NSString stringWithFormat:@"Successfully Deeplinked!\n\nCustom Metadata Deeplink Text: %@\n\nSession Details:\n\n%@",
deeplinkText, [[[Branch getInstance] getLatestReferringParams] description]];
logOutputViewController.logOutput = logOutput;
}
Expand Down Expand Up @@ -175,6 +187,19 @@ - (BOOL)application:(UIApplication *)application
return YES;
}

- (void)setBranchLogFile {
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:@"branchlogs.txt"];

// If the log file already exists, remove it to start fresh
if ([[NSFileManager defaultManager] fileExistsAtPath:logFilePath]) {
[[NSFileManager defaultManager] removeItemAtPath:logFilePath error:nil];
}

self.logFileName = logFilePath;
}


#pragma mark - Push Notifications (Optional)
/*
// Helper method
Expand Down Expand Up @@ -213,10 +238,11 @@ -(void)application:(UIApplication *)application

// hook Function for SDK - Its for taking control of Logging messages.
void APPLogHookFunction(NSDate*_Nonnull timestamp, BranchLogLevel level, NSString*_Nullable message) {
[appDelegate processLogMessage:message];
NSString *formattedMessage = [NSString stringWithFormat:@"%@ [%lu] %@", timestamp, (unsigned long)level, message];
[appDelegate processLogMessage:formattedMessage];
}

// Writes message to log File.
// Writes message to Log File.
- (void) processLogMessage:(NSString *)message {

if (!self.logFileName)
Expand All @@ -228,13 +254,12 @@ - (void) processLogMessage:(NSString *)message {
[fileHandle seekToEndOfFile];
[fileHandle writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandle closeFile];
} else { // Create file if it doesnt exist
} else {
[message writeToFile:self.logFileName
atomically:NO
encoding:NSStringEncodingConversionAllowLossy
error:nil];
}
NSLog(@"%@", message); // Log mmessages to console - remove if required.
}
}

Expand Down
25 changes: 25 additions & 0 deletions Branch-TestBed/Branch-TestBed/LogOutputViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,36 @@ @implementation LogOutputViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.logOutputTextView.text = _logOutput;

UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@"Clear Logs"
style:UIBarButtonItemStylePlain
target:self
action:@selector(clearLogs)];
self.navigationItem.rightBarButtonItem = clearButton;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)clearLogs {
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:@"branchlogs.txt"];

NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtPath:logFilePath error:&error];

if (error) {
NSLog(@"Error clearing log file: %@", error.localizedDescription);
} else {
self.logOutputTextView.text = @"Logs cleared.";
NSLog(@"Log file cleared successfully.");

[self.navigationController popViewControllerAnimated:YES];

}
}


@end
Loading

0 comments on commit 67b02bf

Please sign in to comment.