Skip to content

Commit 67b02bf

Browse files
committed
Release 3.7.0
1 parent 93340fd commit 67b02bf

File tree

24 files changed

+536
-109
lines changed

24 files changed

+536
-109
lines changed

Branch-TestBed/Branch-SDK-Tests/BranchClassTests.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,25 @@ - (void)testSetDMAParamsForEEA {
241241
[[BNCPreferenceHelper sharedInstance] writeObjectToDefaults:@"bnc_dma_ad_user_data" value:nil];
242242
}
243243

244+
- (void)testSetConsumerProtectionAttributionLevel {
245+
// Set to Reduced and check
246+
Branch *branch = [Branch getInstance];
247+
[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced];
248+
XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelReduced);
249+
250+
// Set to Minimal and check
251+
[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelMinimal];
252+
XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelMinimal);
253+
254+
// Set to None and check
255+
[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelNone];
256+
XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelNone);
257+
258+
// Set to Full and check
259+
[branch setConsumerProtectionAttributionLevel:BranchAttributionLevelFull];
260+
XCTAssertEqual([BNCPreferenceHelper sharedInstance].attributionLevel, BranchAttributionLevelFull);
261+
262+
}
263+
264+
244265
@end

Branch-TestBed/Branch-TestBed/AppDelegate.m

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ @implementation AppDelegate
2121
- (BOOL)application:(UIApplication *)application
2222
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2323

24+
[self setBranchLogFile];
25+
2426
appDelegate = self;
2527

2628
/*
@@ -32,20 +34,28 @@ - (BOOL)application:(UIApplication *)application
3234
// Branch.useTestBranchKey = YES; // Make sure to comment this line out for production apps!!!
3335
Branch *branch = [Branch getInstance];
3436

37+
3538
// Change the Branch base API URL
3639
//[Branch setAPIUrl:@"https://api3.branch.io"];
3740

3841
// test pre init support
3942
//[self testDispatchToIsolationQueue:branch]
40-
[branch enableLoggingAtLevel:BranchLogLevelVerbose withCallback:^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) {
43+
44+
45+
[Branch enableLoggingAtLevel:BranchLogLevelVerbose withCallback:^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) {
4146
// Handle the log message and error here. For example, printing to the console:
4247
if (error) {
4348
NSLog(@"[BranchLog] Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription);
4449
} else {
4550
NSLog(@"[BranchLog] Level: %lu, Message: %@", (unsigned long)logLevel, message);
4651
}
52+
53+
NSString *logEntry = error ? [NSString stringWithFormat:@"Level: %lu, Message: %@, Error: %@", (unsigned long)logLevel, message, error.localizedDescription]
54+
: [NSString stringWithFormat:@"Level: %lu, Message: %@", (unsigned long)logLevel, message];
55+
APPLogHookFunction([NSDate date], logLevel, logEntry);
4756
}];
4857

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

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

61-
[self setLogFile:@"OpenNInstall"];
71+
//[self setLogFile:@"OpenNInstall"];
6272

6373
[branch setIdentity:@"Bobby Branch"];
6474

75+
//[[Branch getInstance] setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced];
76+
6577
[branch initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandlerUsingBranchUniversalObject:
6678
^ (BranchUniversalObject * _Nullable universalObject, BranchLinkProperties * _Nullable linkProperties, NSError * _Nullable error) {
6779

68-
[self setLogFile:nil];
80+
//[self setLogFile:nil];
6981
[self handleDeepLinkObject:universalObject linkProperties:linkProperties error:error];
7082
}];
7183

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

190+
- (void)setBranchLogFile {
191+
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
192+
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:@"branchlogs.txt"];
193+
194+
// If the log file already exists, remove it to start fresh
195+
if ([[NSFileManager defaultManager] fileExistsAtPath:logFilePath]) {
196+
[[NSFileManager defaultManager] removeItemAtPath:logFilePath error:nil];
197+
}
198+
199+
self.logFileName = logFilePath;
200+
}
201+
202+
178203
#pragma mark - Push Notifications (Optional)
179204
/*
180205
// Helper method
@@ -213,10 +238,11 @@ -(void)application:(UIApplication *)application
213238

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

219-
// Writes message to log File.
245+
// Writes message to Log File.
220246
- (void) processLogMessage:(NSString *)message {
221247

222248
if (!self.logFileName)
@@ -228,13 +254,12 @@ - (void) processLogMessage:(NSString *)message {
228254
[fileHandle seekToEndOfFile];
229255
[fileHandle writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
230256
[fileHandle closeFile];
231-
} else { // Create file if it doesnt exist
257+
} else {
232258
[message writeToFile:self.logFileName
233259
atomically:NO
234260
encoding:NSStringEncodingConversionAllowLossy
235261
error:nil];
236262
}
237-
NSLog(@"%@", message); // Log mmessages to console - remove if required.
238263
}
239264
}
240265

Branch-TestBed/Branch-TestBed/LogOutputViewController.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,36 @@ @implementation LogOutputViewController
1717
- (void)viewDidLoad {
1818
[super viewDidLoad];
1919
self.logOutputTextView.text = _logOutput;
20+
21+
UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithTitle:@"Clear Logs"
22+
style:UIBarButtonItemStylePlain
23+
target:self
24+
action:@selector(clearLogs)];
25+
self.navigationItem.rightBarButtonItem = clearButton;
2026
}
2127

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

33+
- (void)clearLogs {
34+
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
35+
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:@"branchlogs.txt"];
36+
37+
NSError *error = nil;
38+
[[NSFileManager defaultManager] removeItemAtPath:logFilePath error:&error];
39+
40+
if (error) {
41+
NSLog(@"Error clearing log file: %@", error.localizedDescription);
42+
} else {
43+
self.logOutputTextView.text = @"Logs cleared.";
44+
NSLog(@"Log file cleared successfully.");
45+
46+
[self.navigationController popViewControllerAnimated:YES];
47+
48+
}
49+
}
50+
51+
2752
@end

0 commit comments

Comments
 (0)