Skip to content

Commit

Permalink
Release 1.45.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NidhiDixit09 committed Nov 28, 2022
1 parent e235ec8 commit 4fc2c68
Show file tree
Hide file tree
Showing 24 changed files with 556 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Branch-SDK/BNCConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
NSString * const BNC_API_BASE_URL = @"https://api2.branch.io";
NSString * const BNC_API_VERSION = @"v1";
NSString * const BNC_LINK_URL = @"https://bnc.lt";
NSString * const BNC_SDK_VERSION = @"1.44.0";
NSString * const BNC_SDK_VERSION = @"1.45.0";
5 changes: 5 additions & 0 deletions Branch-SDK/BNCPreferenceHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
@property (assign, nonatomic) NSTimeInterval referrerGBRAIDValidityWindow;
@property (strong, nonatomic) NSDate *referrerGBRAIDInitDate;

@property (assign, nonatomic) NSInteger skanCurrentWindow;
@property (assign, nonatomic) NSInteger highestConversionValueSent;
@property (strong, nonatomic) NSDate *firstAppLaunchTime;
@property (assign, nonatomic) BOOL invokeRegisterApp;

- (void) clearTrackingInformation;

+ (BNCPreferenceHelper *)sharedInstance;
Expand Down
73 changes: 72 additions & 1 deletion Branch-SDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "BNCLog.h"
#import "BranchConstants.h"
#import "NSString+Branch.h"
#import "BNCSKAdNetwork.h"

static const NSTimeInterval DEFAULT_TIMEOUT = 5.5;
static const NSTimeInterval DEFAULT_RETRY_INTERVAL = 0;
Expand Down Expand Up @@ -48,6 +49,10 @@
static NSString * const BRANCH_PREFS_KEY_REFERRER_GBRAID = @"bnc_referrer_gbraid";
static NSString * const BRANCH_PREFS_KEY_REFERRER_GBRAID_WINDOW = @"bnc_referrer_gbraid_window";
static NSString * const BRANCH_PREFS_KEY_REFERRER_GBRAID_INIT_DATE = @"bnc_referrer_gbraid_init_date";
static NSString * const BRANCH_PREFS_KEY_SKAN_CURRENT_WINDOW = @"bnc_skan_current_window";
static NSString * const BRANCH_PREFS_KEY_FIRST_APP_LAUNCH_TIME = @"bnc_first_app_launch_time";
static NSString * const BRANCH_PREFS_KEY_SKAN_HIGHEST_CONV_VALUE_SENT = @"bnc_skan_send_highest_conv_value";
static NSString * const BRANCH_PREFS_KEY_SKAN_INVOKE_REGISTER_APP = @"bnc_invoke_register_app";

NSURL* /* _Nonnull */ BNCURLForBranchDirectory_Unthreaded(void);

Expand Down Expand Up @@ -94,7 +99,10 @@ @implementation BNCPreferenceHelper
requestMetadataDictionary = _requestMetadataDictionary,
instrumentationDictionary = _instrumentationDictionary,
referrerGBRAID = _referrerGBRAID,
referrerGBRAIDValidityWindow = _referrerGBRAIDValidityWindow;
referrerGBRAIDValidityWindow = _referrerGBRAIDValidityWindow,
skanCurrentWindow = _skanCurrentWindow,
firstAppLaunchTime = _firstAppLaunchTime,
highestConversionValueSent = _highestConversionValueSent;

+ (BNCPreferenceHelper *)sharedInstance {
static BNCPreferenceHelper *preferenceHelper;
Expand Down Expand Up @@ -713,6 +721,69 @@ - (void)setReferrerGBRAIDInitDate:(NSDate *)initDate {
}
}

- (NSInteger) skanCurrentWindow {
@synchronized (self) {
_skanCurrentWindow = [self readIntegerFromDefaults:BRANCH_PREFS_KEY_SKAN_CURRENT_WINDOW];
if(_skanCurrentWindow == NSNotFound)
return BranchSkanWindowInvalid;
return _skanCurrentWindow;
}
}

- (void) setSkanCurrentWindow:(NSInteger) window {
@synchronized (self) {
[self writeIntegerToDefaults:BRANCH_PREFS_KEY_SKAN_CURRENT_WINDOW value:window];
}
}


- (NSDate *) firstAppLaunchTime {
@synchronized (self) {
if(!_firstAppLaunchTime) {
_firstAppLaunchTime = (NSDate *)[self readObjectFromDefaults:BRANCH_PREFS_KEY_FIRST_APP_LAUNCH_TIME];
}
return _firstAppLaunchTime;
}
}

- (void) setFirstAppLaunchTime:(NSDate *) launchTime {
@synchronized (self) {
_firstAppLaunchTime = launchTime;
[self writeObjectToDefaults:BRANCH_PREFS_KEY_FIRST_APP_LAUNCH_TIME value:launchTime];
}
}

- (NSInteger) highestConversionValueSent {
@synchronized (self) {
_highestConversionValueSent = [self readIntegerFromDefaults:BRANCH_PREFS_KEY_SKAN_HIGHEST_CONV_VALUE_SENT];
if(_highestConversionValueSent == NSNotFound)
return 0;
return _highestConversionValueSent;
}
}

- (void) setHighestConversionValueSent:(NSInteger)value {
@synchronized (self) {
[self writeIntegerToDefaults:BRANCH_PREFS_KEY_SKAN_HIGHEST_CONV_VALUE_SENT value:value];
}
}

- (BOOL) invokeRegisterApp {
@synchronized (self) {
NSNumber *b = (id) [self readObjectFromDefaults:BRANCH_PREFS_KEY_SKAN_INVOKE_REGISTER_APP];
if ([b isKindOfClass:NSNumber.class]) return [b boolValue];
return false;
}
}

- (void) setInvokeRegisterApp:(BOOL)invoke {
@synchronized(self) {
NSNumber *b = [NSNumber numberWithBool:invoke];
[self writeObjectToDefaults:BRANCH_PREFS_KEY_SKAN_INVOKE_REGISTER_APP value:b];
}
}


- (void) clearTrackingInformation {
@synchronized(self) {
/*
Expand Down
22 changes: 22 additions & 0 deletions Branch-SDK/BNCSKAdNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, BranchSkanWindow) {
BranchSkanWindowInvalid = 0,
BranchSkanWindowFirst = 1,
BranchSkanWindowSecond = 2,
BranchSkanWindowThird = 3
};

@interface BNCSKAdNetwork : NSObject

@property (nonatomic, assign, readwrite) NSTimeInterval maxTimeSinceInstall;
Expand All @@ -23,6 +30,21 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updatePostbackConversionValue:(NSInteger)conversionValue
completionHandler:(void (^)(NSError *error))completion;

- (void)updatePostbackConversionValue:(NSInteger)fineValue
coarseValue:(NSString *) coarseValue
lockWindow:(BOOL)lockWindow
completionHandler:(void (^)(NSError *error))completion API_AVAILABLE(ios(16.1));

- (int) calculateSKANWindowForTime:(NSDate *) currentTime;

- (NSString *) getCoarseConversionValueFromDataResponse:(NSDictionary *) dataResponseDictionary;

- (BOOL) getLockedStatusFromDataResponse:(NSDictionary *) dataResponseDictionary;

- (BOOL) getAscendingOnlyFromDataResponse:(NSDictionary *) dataResponseDictionary;

- (BOOL) shouldCallPostbackForDataResponse:(NSDictionary *) dataResponseDictionary;

@end

NS_ASSUME_NONNULL_END
103 changes: 101 additions & 2 deletions Branch-SDK/BNCSKAdNetwork.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "BNCSKAdNetwork.h"
#import "BNCApplication.h"
#import "BNCPreferenceHelper.h"
#import "BranchConstants.h"

@interface BNCSKAdNetwork()

Expand All @@ -17,6 +19,7 @@ @interface BNCSKAdNetwork()
@property (nonatomic, assign, readwrite) SEL skAdNetworkRegisterAppForAdNetworkAttribution;
@property (nonatomic, assign, readwrite) SEL skAdNetworkUpdateConversionValue;
@property (nonatomic, assign, readwrite) SEL skAdNetworkUpdatePostbackConversionValue;
@property (nonatomic, assign, readwrite) SEL skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow;

@end

Expand All @@ -34,14 +37,21 @@ + (BNCSKAdNetwork *)sharedInstance {
- (instancetype)init {
self = [super init];
if (self) {
// by default, we send updates to SKAdNetwork for up a day after install
self.maxTimeSinceInstall = 3600.0 * 24.0;
if (@available(iOS 16.1, *)){
// For SKAN 4.0, its 60 days = 3600.0 * 24.0 * 60 seconds
self.maxTimeSinceInstall = 3600.0 * 24.0 * 60;
} else {
// by default, we send updates to SKAdNetwork for up a day after install
self.maxTimeSinceInstall = 3600.0 * 24.0;
}

self.installDate = [BNCApplication currentApplication].currentInstallDate;

self.skAdNetworkClass = NSClassFromString(@"SKAdNetwork");
self.skAdNetworkRegisterAppForAdNetworkAttribution = NSSelectorFromString(@"registerAppForAdNetworkAttribution");
self.skAdNetworkUpdateConversionValue = NSSelectorFromString(@"updateConversionValue:");
self.skAdNetworkUpdatePostbackConversionValue = NSSelectorFromString(@"updatePostbackConversionValue:completionHandler:");
self.skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow = NSSelectorFromString(@"updatePostbackConversionValue:coarseValue:lockWindow:completionHandler:");
}
return self;
}
Expand Down Expand Up @@ -91,4 +101,93 @@ - (void)updatePostbackConversionValue:(NSInteger)conversionValue

}

- (void)updatePostbackConversionValue:(NSInteger)fineValue
coarseValue:(NSString *)coarseValue
lockWindow:(BOOL)lockWindow
completionHandler:(void (^)(NSError *error))completion {
if (@available(iOS 16.1, *)) {
if ([self shouldAttemptSKAdNetworkCallout]) {

((id (*)(id, SEL, NSInteger, NSString *, BOOL, void (^)(NSError *error)))[self.skAdNetworkClass methodForSelector:self.skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow])(self.skAdNetworkClass, self.skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow, fineValue, coarseValue, lockWindow, completion);
}
}
}

- (int) calculateSKANWindowForTime:(NSDate *) currentTime{

int firstWindowDuration = 2 * 24 * 3600;
int secondWindowDuration = 7 * 24 * 3600;
int thirdWindowDuration = 35 * 24 * 3600;

NSTimeInterval timeDiff = [currentTime timeIntervalSinceDate:[BNCPreferenceHelper sharedInstance].firstAppLaunchTime];

if (timeDiff <= firstWindowDuration) {
return BranchSkanWindowFirst;
} else if (timeDiff <= secondWindowDuration) {
return BranchSkanWindowSecond;
}else if (timeDiff <= thirdWindowDuration) {
return BranchSkanWindowThird;
}
return BranchSkanWindowInvalid;
}

- (NSString *) getCoarseConversionValueFromDataResponse:(NSDictionary *) dataResponseDictionary{

NSString *coarseConversionValue = dataResponseDictionary[BRANCH_RESPONSE_KEY_COARSE_KEY] ;

if (!coarseConversionValue)
return @"low";

return coarseConversionValue;

}

- (BOOL) getLockedStatusFromDataResponse:(NSDictionary *) dataResponseDictionary {

BOOL lockWin = NO;
if([dataResponseDictionary[BRANCH_RESPONSE_KEY_UPDATE_IS_LOCKED] isKindOfClass:NSNumber.class])
lockWin = ((NSNumber *)dataResponseDictionary[BRANCH_RESPONSE_KEY_UPDATE_IS_LOCKED]).boolValue;
return lockWin;
}

- (BOOL) getAscendingOnlyFromDataResponse:(NSDictionary *) dataResponseDictionary {

BOOL ascendingOnly = YES;
if([dataResponseDictionary[BRANCH_RESPONSE_KEY_ASCENDING_ONLY] isKindOfClass:NSNumber.class])
ascendingOnly = ((NSNumber *)dataResponseDictionary[BRANCH_RESPONSE_KEY_ASCENDING_ONLY]).boolValue;
return ascendingOnly;
}

- (BOOL) shouldCallPostbackForDataResponse:(NSDictionary *) dataResponseDictionary {

BOOL shouldCallUpdatePostback = NO;

if(![BNCPreferenceHelper sharedInstance].invokeRegisterApp)
return shouldCallUpdatePostback;

NSNumber *conversionValue = (NSNumber *)dataResponseDictionary[BRANCH_RESPONSE_KEY_UPDATE_CONVERSION_VALUE];

int currentWindow = [self calculateSKANWindowForTime:[NSDate date]];

if(currentWindow == BranchSkanWindowInvalid)
return shouldCallUpdatePostback;

if ( [BNCPreferenceHelper sharedInstance].skanCurrentWindow < currentWindow) {
[BNCPreferenceHelper sharedInstance].highestConversionValueSent = 0;
[BNCPreferenceHelper sharedInstance].skanCurrentWindow = currentWindow;
}

int highestConversionValue = (int)[BNCPreferenceHelper sharedInstance].highestConversionValueSent;
if( conversionValue.intValue <= highestConversionValue ){
BOOL ascendingOnly = [self getAscendingOnlyFromDataResponse:dataResponseDictionary];
if (!ascendingOnly)
shouldCallUpdatePostback = YES;
} else {
[BNCPreferenceHelper sharedInstance].highestConversionValueSent = conversionValue.intValue;
shouldCallUpdatePostback = YES;
}

return shouldCallUpdatePostback;
}

@end
9 changes: 8 additions & 1 deletion Branch-SDK/BNCServerInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,14 @@ - (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict {
// we do not need to send first_opt_in, if the install is older than 30 days
- (BOOL)installDateIsRecent {
//NSTimeInterval maxTimeSinceInstall = 60.0;
NSTimeInterval maxTimeSinceInstall = 3600.0 * 24.0 * 30;
NSTimeInterval maxTimeSinceInstall = 0;

if (@available(iOS 16.1, *)) {
maxTimeSinceInstall = 3600.0 * 24.0 * 60; // For SKAN 4.0, The user has 60 days to launch the app.
} else {
maxTimeSinceInstall = 3600.0 * 24.0 * 30;
}

NSDate *now = [NSDate date];
NSDate *maxDate = [[BNCApplication currentApplication].currentInstallDate dateByAddingTimeInterval:maxTimeSinceInstall];

Expand Down
2 changes: 1 addition & 1 deletion Branch-SDK/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
Note: Branch does not automatically call SKAdNetwork unless configured on the dashboard.
*/
- (void)setSKAdNetworkCalloutMaxTimeSinceInstall:(NSTimeInterval)maxTimeInterval;
- (void)setSKAdNetworkCalloutMaxTimeSinceInstall:(NSTimeInterval)maxTimeInterval __attribute__((deprecated(("This is no longer supported for iOS 16.1+ - SKAN4.0"))));

/*
Add a Partner Parameter for Facebook.
Expand Down
10 changes: 9 additions & 1 deletion Branch-SDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,11 @@ - (void)handleATTAuthorizationStatus:(NSUInteger)status {
}

- (void)setSKAdNetworkCalloutMaxTimeSinceInstall:(NSTimeInterval)maxTimeInterval {
[BNCSKAdNetwork sharedInstance].maxTimeSinceInstall = maxTimeInterval;
if (@available(iOS 16.1, *)) {
BNCLogDebug(@"This is no longer supported for iOS 16.1+ - SKAN4.0");
} else {
[BNCSKAdNetwork sharedInstance].maxTimeSinceInstall = maxTimeInterval;
}
}

#pragma mark - Partner Parameters
Expand Down Expand Up @@ -1642,6 +1646,10 @@ + (Branch *)getInstanceInternal:(NSString *)key {
[[BNCServerRequestQueue getInstance] clearQueue];
}

if(!preferenceHelper.firstAppLaunchTime){
preferenceHelper.firstAppLaunchTime = [NSDate date];
}

preferenceHelper.lastRunBranchKey = key;
branch =
[[Branch alloc] initWithInterface:[[BNCServerInterface alloc] init]
Expand Down
3 changes: 3 additions & 0 deletions Branch-SDK/BranchConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ extern NSString * const BRANCH_RESPONSE_KEY_BRANCH_VIEW_DATA;
extern NSString * const BRANCH_RESPONSE_KEY_BRANCH_REFERRING_LINK;
extern NSString * const BRANCH_RESPONSE_KEY_INVOKE_REGISTER_APP;
extern NSString * const BRANCH_RESPONSE_KEY_UPDATE_CONVERSION_VALUE;
extern NSString * const BRANCH_RESPONSE_KEY_COARSE_KEY;
extern NSString * const BRANCH_RESPONSE_KEY_UPDATE_IS_LOCKED;
extern NSString * const BRANCH_RESPONSE_KEY_ASCENDING_ONLY;

extern NSString * const BRANCH_LINK_DATA_KEY_OG_TITLE;
extern NSString * const BRANCH_LINK_DATA_KEY_OG_DESCRIPTION;
Expand Down
3 changes: 3 additions & 0 deletions Branch-SDK/BranchConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
NSString * const BRANCH_RESPONSE_KEY_BRANCH_REFERRING_LINK = @"~referring_link";
NSString * const BRANCH_RESPONSE_KEY_INVOKE_REGISTER_APP = @"invoke_register_app";
NSString * const BRANCH_RESPONSE_KEY_UPDATE_CONVERSION_VALUE = @"update_conversion_value";
NSString * const BRANCH_RESPONSE_KEY_COARSE_KEY = @"coarse_key";
NSString * const BRANCH_RESPONSE_KEY_UPDATE_IS_LOCKED = @"locked";
NSString * const BRANCH_RESPONSE_KEY_ASCENDING_ONLY = @"ascending_only";

NSString * const BRANCH_LINK_DATA_KEY_OG_TITLE = @"$og_title";
NSString * const BRANCH_LINK_DATA_KEY_OG_DESCRIPTION = @"$og_description";
Expand Down
Loading

0 comments on commit 4fc2c68

Please sign in to comment.