Skip to content

Commit

Permalink
testbed updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Nov 6, 2024
1 parent 6a0293a commit f4b18dd
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 23 deletions.
33 changes: 27 additions & 6 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 @@ -44,9 +46,14 @@ - (BOOL)application:(UIApplication *)application
// 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);
//Add to file here
} 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);
}];


Expand All @@ -62,16 +69,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 setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced];
//[[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 @@ -140,7 +147,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 @@ -181,6 +188,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 @@ -219,7 +239,8 @@ -(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.
Expand All @@ -240,7 +261,7 @@ - (void) processLogMessage:(NSString *)message {
encoding:NSStringEncodingConversionAllowLossy
error:nil];
}
NSLog(@"%@", message); // Log mmessages to console - remove if required.
NSLog(@"%@", message); // Log messages 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
28 changes: 14 additions & 14 deletions Branch-TestBed/Branch-TestBed/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="rgL-wI-yV3">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="rgL-wI-yV3">
<device id="retina4_7" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -535,7 +535,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="L2t-YG-cpE">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="L2t-YG-cpE">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand All @@ -562,7 +562,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JRt-Kp-qAQ">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JRt-Kp-qAQ">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand All @@ -589,7 +589,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="467-af-xm1">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="467-af-xm1">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand All @@ -616,7 +616,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="PnJ-Tp-Oq2">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="PnJ-Tp-Oq2">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand Down Expand Up @@ -647,7 +647,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JXr-9x-vX0">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JXr-9x-vX0">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand All @@ -674,7 +674,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jWK-QY-Hr2">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jWK-QY-Hr2">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand All @@ -701,11 +701,11 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="t8S-Z0-hG9">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="t8S-Z0-hG9">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
<state key="normal" title="Load Logs for Last Command" image="doc.text" catalog="system">
<state key="normal" title="Load Branch Logs" image="doc.text" catalog="system">
<color key="titleColor" systemColor="linkColor"/>
</state>
<connections>
Expand All @@ -728,7 +728,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7Rz-jF-ETn">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7Rz-jF-ETn">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<accessibility key="accessibilityConfiguration" identifier="tracking"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand Down Expand Up @@ -756,7 +756,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cLu-WM-Ib5">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cLu-WM-Ib5">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="20" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand All @@ -783,7 +783,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="UTG-yQ-PWO">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="UTG-yQ-PWO">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<accessibility key="accessibilityConfiguration" identifier="tracking"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand Down Expand Up @@ -811,7 +811,7 @@
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oFC-oS-hU2">
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oFC-oS-hU2">
<rect key="frame" x="0.0" y="0.0" width="343" height="44"/>
<accessibility key="accessibilityConfiguration" identifier="tracking"/>
<inset key="titleEdgeInsets" minX="30" minY="0.0" maxX="0.0" maxY="0.0"/>
Expand Down
Loading

0 comments on commit f4b18dd

Please sign in to comment.