Skip to content

Commit

Permalink
Release 3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Jul 24, 2024
1 parent 0df3ec6 commit ffa4337
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 13 deletions.
2 changes: 1 addition & 1 deletion BranchSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "BranchSDK"
s.version = "3.4.4"
s.version = "3.5.0"
s.summary = "Create an HTTP URL for any piece of content in your app"
s.description = <<-DESC
- Want the highest possible conversions on your sharing feature?
Expand Down
12 changes: 6 additions & 6 deletions BranchSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 3.4.4;
MARKETING_VERSION = 3.5.0;
OTHER_LDFLAGS = (
"-weak_framework",
LinkPresentation,
Expand Down Expand Up @@ -2009,7 +2009,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 3.4.4;
MARKETING_VERSION = 3.5.0;
OTHER_LDFLAGS = (
"-weak_framework",
LinkPresentation,
Expand Down Expand Up @@ -2215,7 +2215,7 @@
"@loader_path/Frameworks",
);
MACH_O_TYPE = staticlib;
MARKETING_VERSION = 3.4.4;
MARKETING_VERSION = 3.5.0;
OTHER_LDFLAGS = (
"-weak_framework",
LinkPresentation,
Expand Down Expand Up @@ -2254,7 +2254,7 @@
"@loader_path/Frameworks",
);
MACH_O_TYPE = staticlib;
MARKETING_VERSION = 3.4.4;
MARKETING_VERSION = 3.5.0;
OTHER_LDFLAGS = (
"-weak_framework",
LinkPresentation,
Expand Down Expand Up @@ -2291,7 +2291,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 3.4.4;
MARKETING_VERSION = 3.5.0;
OTHER_LDFLAGS = (
"-weak_framework",
LinkPresentation,
Expand Down Expand Up @@ -2326,7 +2326,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 3.4.4;
MARKETING_VERSION = 3.5.0;
OTHER_LDFLAGS = (
"-weak_framework",
LinkPresentation,
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Branch iOS SDK Change Log

v.3.5.0
- Add additional logging
- Update setRequestMetadata signature to use NSString

v.3.4.4
- Fix for rare case where Branch events were duplicated
- Fixed script in "Run Script" phase of static framework targets
Expand Down
2 changes: 1 addition & 1 deletion Sources/BranchSDK/BNCConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "BNCConfig.h"

NSString * const BNC_SDK_VERSION = @"3.4.4";
NSString * const BNC_SDK_VERSION = @"3.5.0";
NSString * const BNC_LINK_URL = @"https://bnc.lt";
NSString * const BNC_CDN_URL = @"https://cdn.branch.io";

Expand Down
3 changes: 3 additions & 0 deletions Sources/BranchSDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,11 @@ - (NSString *)sessionParams {

- (void)setSessionParams:(NSString *)sessionParams {
@synchronized (self) {
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Setting session params %@", sessionParams] error:nil];
if (sessionParams == nil || ![_sessionParams isEqualToString:sessionParams]) {
_sessionParams = sessionParams;
[self writeObjectToDefaults:BRANCH_PREFS_KEY_SESSION_PARAMS value:sessionParams];
[[BranchLogger shared] logVerbose:@"Params set" error:nil];
}
}
}
Expand Down Expand Up @@ -845,6 +847,7 @@ - (void) clearTrackingInformation {
self.userIdentity = nil;
self.referringURLQueryParameters = nil;
self.anonID = nil;
[[BranchLogger shared] logVerbose:@"Tracking information cleared" error:nil];
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/BranchSDK/BNCReferringURLUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ - (void)dealloc {


- (void)parseReferringURL:(NSURL *)url {
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Parsing URL %@", url] error:nil];

NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
for (NSURLQueryItem *item in components.queryItems) {
if ([self isSupportedQueryParameter:item.name]) {
Expand Down
11 changes: 10 additions & 1 deletion Sources/BranchSDK/BNCServerInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ - (void)postRequest:(NSDictionary *)post url:(NSString *)url key:(NSString *)key

- (void)postRequest:(NSDictionary *)post url:(NSString *)url retryNumber:(NSInteger)retryNumber key:(NSString *)key callback:(BNCServerCallback)callback {

[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"retryNumber %ld", retryNumber] error:nil];

// TODO: confirm it's ok to send full URL instead of with the domain trimmed off
self.requestEndpoint = url;
NSURLRequest *request = [self preparePostRequest:post url:url key:key retryNumber:retryNumber];
Expand Down Expand Up @@ -124,6 +126,8 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
if (status != 200) {
if ([NSError branchDNSBlockingError:underlyingError]) {
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Possible DNS Ad Blocker. Giving up on request with HTTP status code %ld", (long)status] error:underlyingError];
} else if ([NSError branchVPNBlockingError:underlyingError]) {
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Possible VPN Ad Blocker. Giving up on request with HTTP status code %ld", (long)status] error:underlyingError];
} else {
[[BranchLogger shared] logWarning: [NSString stringWithFormat:@"Giving up on request with HTTP status code %ld", (long)status] error:underlyingError];
}
Expand All @@ -139,7 +143,8 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
// Drops non-linking requests when tracking is disabled
if (Branch.trackingDisabled) {
NSString *endpoint = request.URL.absoluteString;

[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Tracking is disabled, checking if %@ is linking request.", endpoint] error:nil];

if (![self isLinkingRelatedRequest:endpoint]) {
[[BNCPreferenceHelper sharedInstance] clearTrackingInformation];
NSError *error = [NSError branchErrorWithCode:BNCTrackingDisabledError];
Expand Down Expand Up @@ -290,6 +295,10 @@ - (BNCServerResponse *)processServerResponse:(NSURLResponse *)response data:(NSD
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSString *requestId = httpResponse.allHeaderFields[@"X-Branch-Request-Id"];

if ([[BranchLogger shared] shouldLog:BranchLogLevelVerbose]) {
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Processing response %@", requestId] error:nil];
}

if (!error) {
serverResponse.statusCode = @([httpResponse statusCode]);
serverResponse.data = [BNCEncodingUtils decodeJsonDataToDictionary:data];
Expand Down
2 changes: 2 additions & 0 deletions Sources/BranchSDK/BNCURLFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ - (BOOL)foundUpdatedURLList:(id<BNCNetworkOperationProtocol>)operation {
} else if (statusCode != 200 || error != nil || jsonString == nil) {
if ([NSError branchDNSBlockingError:error]) {
[[BranchLogger shared] logWarning:@"Possible DNS Ad Blocker" error:error];
} else if ([NSError branchVPNBlockingError:error]) {
[[BranchLogger shared] logWarning:@"Possible VPN Ad Blocker" error:error];
} else {
[[BranchLogger shared] logWarning:@"Failed to update URL ignore list" error:operation.error];
}
Expand Down
29 changes: 28 additions & 1 deletion Sources/BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ - (void)setRetryInterval:(NSTimeInterval)retryInterval {
}


- (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value {
- (void)setRequestMetadataKey:(NSString *)key value:(NSString *)value {
[self.preferenceHelper setRequestMetadataKey:key value:value];
}

Expand All @@ -504,6 +504,8 @@ + (BOOL)trackingDisabled {

+ (void)setTrackingDisabled:(BOOL)disabled {
@synchronized(self) {
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"setTrackingDisabled to %d", disabled] error:nil];

BOOL currentSetting = self.trackingDisabled;
if (!!currentSetting == !!disabled)
return;
Expand All @@ -515,6 +517,8 @@ + (void)setTrackingDisabled:(BOOL)disabled {
Branch *branch = Branch.getInstance;
[branch clearNetworkQueue];
branch.initializationStatus = BNCInitStatusUninitialized;
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", branch.initializationStatus] error:nil];

[branch.linkCache clear];
// Release the lock in case it's locked:
[BranchOpenRequest releaseOpenResponseLock];
Expand Down Expand Up @@ -668,10 +672,12 @@ - (BOOL)handleDeepLink:(NSURL *)url {
}

- (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier {
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Handle deep link %@", url] error:nil];

// we've been resetting the session on all deeplinks for quite some time
// this allows foreground links to callback
self.initializationStatus = BNCInitStatusUninitialized;
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil];

//Check the referring url/uri for query parameters and save them
BNCReferringURLUtility *utility = [BNCReferringURLUtility new];
Expand Down Expand Up @@ -702,6 +708,8 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier
- (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sceneIdentifier {
BOOL handled = NO;
self.preferenceHelper.referringURL = nil;
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set referringURL to %@", self.preferenceHelper.referringURL] error:nil];

if (url && ![url isEqual:[NSNull null]]) {

NSString *urlScheme = [url scheme];
Expand All @@ -712,12 +720,14 @@ - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sce
if (urlScheme && [scheme isEqualToString:urlScheme]) {
self.preferenceHelper.externalIntentURI = [url absoluteString];
self.preferenceHelper.referringURL = [url absoluteString];
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Allowed scheme list, set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil];
break;
}
}
} else {
self.preferenceHelper.externalIntentURI = [url absoluteString];
self.preferenceHelper.referringURL = [url absoluteString];
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil];
}

NSString *query = [url fragment];
Expand Down Expand Up @@ -762,6 +772,7 @@ - (BOOL)handleUniversalDeepLink_private:(NSString*)urlString sceneIdentifier:(NS
if (urlString.length) {
self.preferenceHelper.universalLinkUrl = urlString;
self.preferenceHelper.referringURL = urlString;
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set universalLinkUrl and referringURL to %@", urlString] error:nil];
}

[self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:urlString];
Expand Down Expand Up @@ -1699,16 +1710,25 @@ - (void)applicationDidBecomeActive {
dispatch_async(self.isolationQueue, ^(){
// if necessary, creates a new organic open
BOOL installOrOpenInQueue = [self.requestQueue containsInstallOrOpen];

[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationDidBecomeActive installOrOpenInQueue %d", installOrOpenInQueue] error:nil];

if (!Branch.trackingDisabled && self.initializationStatus != BNCInitStatusInitialized && !installOrOpenInQueue) {
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationDidBecomeActive trackingDisabled %d initializationStatus %d installOrOpenInQueue %d", Branch.trackingDisabled, self.initializationStatus, installOrOpenInQueue] error:nil];

[self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil];
}
});
}

- (void)applicationWillResignActive {
[[BranchLogger shared] logVerbose:@"applicationWillResignActive" error:nil];

dispatch_async(self.isolationQueue, ^(){
if (!Branch.trackingDisabled) {
self.initializationStatus = BNCInitStatusUninitialized;
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationWillResignActive initializationStatus %ld", self.initializationStatus] error:nil];

[self.requestQueue persistImmediately];
[BranchOpenRequest setWaitNeededForOpenResponseLock];
}
Expand Down Expand Up @@ -1842,6 +1862,8 @@ - (void)processNextQueueItem {
self.networkCount = 1;
dispatch_semaphore_signal(self.processing_sema);
BNCServerRequest *req = [self.requestQueue peek];

[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Processing %@", req]error:nil];

if (req) {

Expand Down Expand Up @@ -2035,6 +2057,8 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
}

self.initializationStatus = BNCInitStatusInitializing;
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil];

[self processNextQueueItem];
});
}
Expand All @@ -2044,6 +2068,8 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
- (void)handleInitSuccessAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier {

self.initializationStatus = BNCInitStatusInitialized;
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil];

NSDictionary *latestReferringParams = [self getLatestReferringParams];

if ([latestReferringParams[@"_branch_validate"] isEqualToString:@"060514"]) {
Expand Down Expand Up @@ -2260,6 +2286,7 @@ - (void)presentSharingViewController:(UIViewController <BranchDeepLinkingControl

- (void)handleInitFailure:(NSError *)error callCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier {
self.initializationStatus = BNCInitStatusUninitialized;
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil];

if (callCallback) {
if (self.sceneSessionInitWithCallback) {
Expand Down
2 changes: 2 additions & 0 deletions Sources/BranchSDK/BranchQRCode.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ - (void)callQRCodeAPI:(nullable NSDictionary *)params
if (error) {
if ([NSError branchDNSBlockingError:error]) {
[[BranchLogger shared] logWarning:@"Possible DNS Ad Blocker" error:error];
} else if ([NSError branchVPNBlockingError:error]) {
[[BranchLogger shared] logWarning:@"Possible VPN Ad Blocker" error:error];
} else {
[[BranchLogger shared] logError:@"QR Code request failed" error:error];
completion(nil, error);
Expand Down
46 changes: 46 additions & 0 deletions Sources/BranchSDK/NSError+Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,50 @@ + (BOOL)branchDNSBlockingError:(NSError *)error {
return NO;
}

+ (BOOL)branchVPNBlockingError:(NSError *)error {
if (error) {
NSError *underlyingError = error.userInfo[@"NSUnderlyingError"];
if (underlyingError) {

/**
`Domain=kCFErrorDomainCFNetwork Code=-1004` indicates that the connection failed because a connection can't be made to the host.
Reference: https://developer.apple.com/documentation/cfnetwork/cfnetworkerrors/kcfurlerrorcannotconnecttohost?language=objc
`_kCFStreamErrorCodeKey=61` indicates that the connection was refused.
Reference: https://opensource.apple.com/source/xnu/xnu-792/bsd/sys/errno.h.auto.html
*/

BOOL isCouldntConnectErrorCode = [@(-1004) isEqual:@(underlyingError.code)];
BOOL isLocalHostErrorKey = [@(61) isEqual:error.userInfo[@"_kCFStreamErrorCodeKey"]];

if ([self isConnectedToVPN] && isCouldntConnectErrorCode && isLocalHostErrorKey) {
return YES;
}
}
}
return NO;
}

/**
Helper method to which checks the device's internet proxy settings for common VPN protocol and interface substrings to determine if a VPN enabled.
https://developer.apple.com/documentation/cfnetwork/cfnetworkcopysystemproxysettings()
*/
+ (BOOL)isConnectedToVPN {
NSDictionary *proxySettings = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings());
if (proxySettings) {
NSDictionary *scopedSettings = proxySettings[@"__SCOPED__"];
if (scopedSettings) {
for (NSString *key in scopedSettings) {
if ([key containsString:@"tap"] ||
[key containsString:@"tun"] ||
[key containsString:@"ppp"] ||
[key containsString:@"ipsec"]) {
return YES;
}
}
}
}
return NO;
}

@end
3 changes: 3 additions & 0 deletions Sources/BranchSDK/Private/NSError+Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ typedef NS_ENUM(NSInteger, BNCErrorCode) {
// Checks if an NSError looks like a DNS blocking error
+ (BOOL)branchDNSBlockingError:(NSError *)error;

// Checks if an NSError looks like a VPN blocking error
+ (BOOL)branchVPNBlockingError:(NSError *)error;

@end

NS_ASSUME_NONNULL_END
Expand Down
4 changes: 2 additions & 2 deletions Sources/BranchSDK/Public/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,9 @@ Sets a custom base URL for all calls to the Branch API.
Key-value pairs to be included in the metadata on every request.
@param key String to be included in request metadata
@param value Object to be included in request metadata
@param value Value to be included in request metadata
*/
- (void)setRequestMetadataKey:(NSString *)key value:(nullable id)value;
- (void)setRequestMetadataKey:(NSString *)key value:(nullable NSString *)value;

/**
Disables the Branch SDK from tracking the user. This is useful for GDPR privacy compliance.
Expand Down
2 changes: 1 addition & 1 deletion scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Options:
USAGE
}

version=3.4.4
version=3.5.0
prev_version="$version"

if (( $# == 0 )); then
Expand Down

0 comments on commit ffa4337

Please sign in to comment.