Skip to content

Commit

Permalink
Merge branch 'master' into mobileboost
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Dec 19, 2024
2 parents 5497a5d + 5ae2b4d commit 340b47d
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 18 deletions.
12 changes: 10 additions & 2 deletions Branch-TestBed/Branch-TestBed/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,23 @@ - (BOOL)application:(UIApplication *)application
// test pre init support
//[self testDispatchToIsolationQueue:branch]


[Branch enableLoggingAtLevel:BranchLogLevelVerbose withCallback:^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) {
[Branch enableLoggingAtLevel:BranchLogLevelVerbose withAdvancedCallback:^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error, NSMutableURLRequest * _Nullable request, BNCServerResponse * _Nullable response) {
// 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);
}

if (request) {
NSString *jsonString = [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding];
NSLog(@"[BranchLog] Got %@ Request: %@", request.URL , jsonString);
}

if (response) {
NSLog(@"[BranchLog] Got Response for request (%@): %@", response.requestId, response.data);
}

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 Down
4 changes: 2 additions & 2 deletions Sources/BranchSDK/BNCServerInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ - (NSURLRequest *)preparePostRequest:(NSDictionary *)params url:(NSString *)url
[request setHTTPBody:postData];

if ([[BranchLogger shared] shouldLog:BranchLogLevelDebug]) {
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"%@\nHeaders %@\nBody %@", request, [request allHTTPHeaderFields], [BNCEncodingUtils prettyPrintJSON:updatedParams]] error:nil];
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"%@\nHeaders %@\nBody %@", request, [request allHTTPHeaderFields], [BNCEncodingUtils prettyPrintJSON:updatedParams]] error:nil request:request response:nil];
}

return request;
Expand All @@ -310,7 +310,7 @@ - (BNCServerResponse *)processServerResponse:(NSURLResponse *)response data:(NSD
serverResponse.requestId = requestId;

if ([[BranchLogger shared] shouldLog:BranchLogLevelDebug]) {
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"%@\nBody %@", response, [BNCEncodingUtils prettyPrintJSON:serverResponse.data]] error:nil];
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"%@\nBody %@", response, [BNCEncodingUtils prettyPrintJSON:serverResponse.data]] error:nil request:nil response:serverResponse];
}

} else {
Expand Down
33 changes: 28 additions & 5 deletions Sources/BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@ - (id)initWithInterface:(BNCServerInterface *)interface
if (config.checkPasteboardOnInstall) {
[self checkPasteboardOnInstall];
}

if (config.cppLevel) {
if ([config.cppLevel caseInsensitiveCompare:@"FULL"] == NSOrderedSame) {
[[Branch getInstance] setConsumerProtectionAttributionLevel:BranchAttributionLevelFull];
} else if ([config.cppLevel caseInsensitiveCompare:@"REDUCED"] == NSOrderedSame) {
[[Branch getInstance] setConsumerProtectionAttributionLevel:BranchAttributionLevelReduced];
} else if ([config.cppLevel caseInsensitiveCompare:@"MINIMAL"] == NSOrderedSame) {
[[Branch getInstance] setConsumerProtectionAttributionLevel:BranchAttributionLevelMinimal];
} else if ([config.cppLevel caseInsensitiveCompare:@"NONE"] == NSOrderedSame) {
[[Branch getInstance] setConsumerProtectionAttributionLevel:BranchAttributionLevelNone];
} else {
NSLog(@"Invalid CPP Level set in branch.json: %@", config.cppLevel);
}
}

return self;
}
Expand Down Expand Up @@ -455,6 +469,15 @@ + (void)enableLoggingAtLevel:(BranchLogLevel)logLevel withCallback:(nullable Bra
}
}

+ (void)enableLoggingAtLevel:(BranchLogLevel)logLevel withAdvancedCallback:(nullable BranchAdvancedLogCallback)callback {
BranchLogger *logger = [BranchLogger shared];
logger.loggingEnabled = YES;
logger.logLevelThreshold = logLevel;
if (callback) {
logger.advancedLogCallback = callback;
}
}

- (void)useEUEndpoints {
[BNCServerAPI sharedInstance].useEUServers = YES;
}
Expand Down Expand Up @@ -632,7 +655,7 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options automaticallyDispla

#pragma mark - Actual Init Session

- (void)initSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)isReferrable explicitlyRequestedReferrable:(BOOL)explicitlyRequestedReferrable automaticallyDisplayController:(BOOL)automaticallyDisplayController registerDeepLinkHandlerUsingBranchUniversalObject:(callbackWithBranchUniversalObject)callback {
- (void)initSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)isReferrable explicitlyRequestedReferrable:(BOOL)explicitlyRequestedReferrable automaticallyDisplayController:(BOOL)automaticallyDisplayController registerDeepLinkHandlerUsingBranchUniversalObject:(callbackWithBranchUniversalObject)callback {
[self initSceneSessionWithLaunchOptions:options isReferrable:isReferrable explicitlyRequestedReferrable:explicitlyRequestedReferrable automaticallyDisplayController:automaticallyDisplayController
registerDeepLinkHandler:^(BNCInitSessionResponse * _Nullable initResponse, NSError * _Nullable error) {
if (callback) {
Expand Down Expand Up @@ -1107,8 +1130,8 @@ - (NSDictionary *)getFirstReferringParams {

if (self.deepLinkDebugParams) {
NSMutableDictionary* debugInstallParams =
[[BNCEncodingUtils decodeJsonStringToDictionary:self.preferenceHelper.sessionParams]
mutableCopy];
[[BNCEncodingUtils decodeJsonStringToDictionary:self.preferenceHelper.sessionParams]
mutableCopy];
[debugInstallParams addEntriesFromDictionary:self.deepLinkDebugParams];
return debugInstallParams;
}
Expand Down Expand Up @@ -2051,7 +2074,7 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr
// only called from initUserSessionAndCallCallback!
- (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString {

// BranchDelegate willStartSessionWithURL notification
// BranchDelegate willStartSessionWithURL notification
NSURL *URL = (self.preferenceHelper.referringURL.length) ? [NSURL URLWithString:self.preferenceHelper.referringURL] : nil;
if ([self.delegate respondsToSelector:@selector(branch:willStartSessionWithURL:)]) {
[self.delegate branch:self willStartSessionWithURL:URL];
Expand Down Expand Up @@ -2116,7 +2139,7 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS

[self processNextQueueItem];
});
}
}
}


Expand Down
7 changes: 6 additions & 1 deletion Sources/BranchSDK/BranchJsonConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
NSString * _Nonnull const BranchJsonConfigEnableLogging = @"enableLogging";
NSString * _Nonnull const BranchJsonConfigCheckPasteboardOnInstall = @"checkPasteboardOnInstall";
NSString * _Nonnull const BranchJsonConfigAPIUrl = @"apiUrl";

NSString * _Nonnull const BranchJsonConfigCPPLevel = @"consumerProtectionAttributionLevel";

@interface BranchJsonConfig()
@property (nonatomic, strong) NSDictionary *configuration;
Expand Down Expand Up @@ -163,6 +163,11 @@ - (NSString *)apiUrl
return self[BranchJsonConfigAPIUrl];
}

- (NSString *)cppLevel
{
return self[BranchJsonConfigCPPLevel];
}

- (id)objectForKey:(NSString *)key
{
return self.configuration[key];
Expand Down
25 changes: 17 additions & 8 deletions Sources/BranchSDK/BranchLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,29 @@ - (void)disableCallerDetails {
}

- (void)logError:(NSString *)message error:(NSError *_Nullable)error {
[self logMessage:message withLevel:BranchLogLevelError error:error];
[self logMessage:message withLevel:BranchLogLevelError error:error request:nil response:nil];
}

- (void)logWarning:(NSString *)message error:(NSError *_Nullable)error {
[self logMessage:message withLevel:BranchLogLevelWarning error:error];
[self logMessage:message withLevel:BranchLogLevelWarning error:error request:nil response:nil];
}

- (void)logDebug:(NSString *)message error:(NSError *_Nullable)error {
[self logMessage:message withLevel:BranchLogLevelDebug error:error];
- (void)logDebug:(NSString * _Nonnull)message error:(NSError * _Nullable)error {
[self logDebug:message error:error request:nil response:nil];
}

- (void)logDebug:(NSString * _Nonnull)message
error:(NSError * _Nullable)error
request:(NSMutableURLRequest * _Nullable)request
response:(BNCServerResponse * _Nullable)response {
[self logMessage:message withLevel:BranchLogLevelDebug error:error request:request response:response];
}

- (void)logVerbose:(NSString *)message error:(NSError *_Nullable)error {
[self logMessage:message withLevel:BranchLogLevelVerbose error:error];
[self logMessage:message withLevel:BranchLogLevelVerbose error:error request:nil response:nil];
}

- (void)logMessage:(NSString *)message withLevel:(BranchLogLevel)level error:(NSError *_Nullable)error {
- (void)logMessage:(NSString *)message withLevel:(BranchLogLevel)level error:(NSError *_Nullable)error request:(NSMutableURLRequest * _Nullable)request response:(BNCServerResponse * _Nullable)response {
if (!self.loggingEnabled || level < self.logLevelThreshold || message.length == 0) {
return;
}
Expand All @@ -77,8 +84,10 @@ - (void)logMessage:(NSString *)message withLevel:(BranchLogLevel)level error:(NS
if (self.includeCallerDetails) {
formattedMessage = [NSString stringWithFormat:@"%@ %@", [self callingClass], message];
}

if (self.logCallback) {

if (self.advancedLogCallback) {
self.advancedLogCallback(formattedMessage, level, error, request, response);
} else if (self.logCallback) {
self.logCallback(formattedMessage, level, error);
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/BranchSDK/Private/BranchJsonConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern NSString * _Nonnull const BranchJsonConfigAPIUrl;
@property (nonatomic, readonly, assign) BOOL enableLogging;
@property (nonatomic, readonly, assign) BOOL checkPasteboardOnInstall;
@property (nonatomic, readonly, nullable, copy) NSString *apiUrl;
@property (nonatomic, readonly, nullable, copy) NSString *cppLevel;

- (nullable id)objectForKey:(NSString * _Nonnull)key;
- (nullable id)objectForKeyedSubscript:(NSString * _Nonnull)key;
Expand Down
1 change: 1 addition & 0 deletions Sources/BranchSDK/Public/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ extern NSString * __nonnull const BNCSpotlightFeature;
*/
+ (void)enableLogging;
+ (void)enableLoggingAtLevel:(BranchLogLevel)logLevel withCallback:(nullable BranchLogCallback)callback;
+ (void)enableLoggingAtLevel:(BranchLogLevel)logLevel withAdvancedCallback:(nullable BranchAdvancedLogCallback)callback;

// The new logging system is independent of the Branch singleton and can be called earlier.
- (void)enableLogging __attribute__((deprecated(("This API is deprecated. Please use the static version."))));
Expand Down
4 changes: 4 additions & 0 deletions Sources/BranchSDK/Public/BranchLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <Foundation/Foundation.h>
#import "BNCServerResponse.h"

typedef NS_ENUM(NSUInteger, BranchLogLevel) {
BranchLogLevelVerbose, // development
Expand All @@ -16,6 +17,7 @@ typedef NS_ENUM(NSUInteger, BranchLogLevel) {
};

typedef void(^BranchLogCallback)(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error);
typedef void(^BranchAdvancedLogCallback)(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error, NSMutableURLRequest * _Nullable request, BNCServerResponse * _Nullable response);

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -24,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) BOOL loggingEnabled;
@property (nonatomic, assign) BOOL includeCallerDetails;
@property (nonatomic, copy, nullable) BranchLogCallback logCallback;
@property (nonatomic, copy, nullable) BranchAdvancedLogCallback advancedLogCallback;
@property (nonatomic, assign) BranchLogLevel logLevelThreshold;

+ (instancetype _Nonnull)shared;
Expand All @@ -37,6 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)logError:(NSString * _Nonnull)message error:(NSError * _Nullable)error;
- (void)logWarning:(NSString * _Nonnull)message error:(NSError * _Nullable)error;
- (void)logDebug:(NSString * _Nonnull)message error:(NSError * _Nullable)error;
- (void)logDebug:(NSString * _Nonnull)message error:(NSError * _Nullable)error request:(NSMutableURLRequest * _Nullable)request response:(BNCServerResponse * _Nullable)response;
- (void)logVerbose:(NSString * _Nonnull)message error:(NSError * _Nullable)error;

// default Branch log format
Expand Down

0 comments on commit 340b47d

Please sign in to comment.