Skip to content

Commit 766f456

Browse files
committed
SDK-550 repurposed old update flag to indicate an app that migrates from Tune SDK to Branch SDK.
1 parent 9b86cba commit 766f456

File tree

4 files changed

+28
-44
lines changed

4 files changed

+28
-44
lines changed

Branch-SDK-Tests/BranchOpenRequestTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ - (void)testRequestBodyWithNoFingerprintID {
9393
@"lastest_update_time": BNCWireFormatFromDate(installDate),
9494
@"first_install_time": BNCWireFormatFromDate(installDate),
9595
@"previous_update_time": BNCWireFormatFromDate(updateDate),
96-
@"update": @1,
96+
@"update": @0,
9797
@"apple_testflight": @0
9898
}];
9999
if (!self.class.isApplication) expectedParams[@"ios_team_id"] = nil;
@@ -174,7 +174,7 @@ - (void)testRequestBodyWithFingerprintID {
174174
@"lastest_update_time": BNCWireFormatFromDate(installDate),
175175
@"first_install_time": BNCWireFormatFromDate(installDate),
176176
@"previous_update_time": BNCWireFormatFromDate(updateDate),
177-
@"update": @1,
177+
@"update": @0,
178178
@"apple_testflight": @0
179179
}];
180180
if (!self.class.isApplication) expectedParams[@"ios_team_id"] = nil;

Branch-SDK/Branch-SDK/BNCTuneUtility.m

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ @implementation BNCTuneUtility
1212

1313
// INTENG-7695 Tune data indicates an app upgrading from Tune SDK to Branch SDK
1414
+ (BOOL)isTuneDataPresent {
15-
NSString *tuneMatIdKey = @"_TUNE_mat_id";
16-
NSString *matId = [[NSUserDefaults standardUserDefaults] stringForKey:tuneMatIdKey];
17-
if (matId && [matId length] > 0) {
18-
return YES;
19-
}
20-
return NO;
15+
__block BOOL isPresent = NO;
16+
static dispatch_once_t onceToken;
17+
dispatch_once(&onceToken, ^{
18+
NSString *tuneMatIdKey = @"_TUNE_mat_id";
19+
NSString *matId = [[NSUserDefaults standardUserDefaults] stringForKey:tuneMatIdKey];
20+
if (matId && [matId length] > 0) {
21+
isPresent = YES;
22+
}
23+
});
24+
return isPresent;
2125
}
2226

2327
@end

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#import "BNCURLBlackList.h"
4343
#import "BNCUserAgentCollector.h"
4444
#import "BNCDeviceInfo.h"
45-
#import "BNCTuneUtility.h"
4645
#import <stdatomic.h>
4746

4847
NSString * const BRANCH_FEATURE_TAG_SHARE = @"share";
@@ -2251,7 +2250,7 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback {
22512250

22522251
- (void)initializeSession {
22532252
Class clazz = [BranchInstallRequest class];
2254-
if (self.preferenceHelper.identityID || [BNCTuneUtility isTuneDataPresent]) {
2253+
if (self.preferenceHelper.identityID) {
22552254
clazz = [BranchOpenRequest class];
22562255
}
22572256

Branch-SDK/Branch-SDK/Networking/Requests/BranchOpenRequest.m

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#import "Branch.h"
1919
#import "BNCApplication.h"
2020
#import "BNCAppleReceipt.h"
21+
#import "BNCTuneUtility.h"
2122

2223
@interface BranchOpenRequest ()
2324
@property (assign, nonatomic) BOOL isInstall;
@@ -99,42 +100,22 @@ - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key ca
99100
}
100101

101102
typedef NS_ENUM(NSInteger, BNCUpdateState) {
102-
BNCUpdateStateInstall = 0, // App was recently installed.
103-
BNCUpdateStateNonUpdate = 1, // App was neither newly installed nor updated.
104-
BNCUpdateStateUpdate = 2, // App was recently updated.
105-
106-
// BNCUpdateStateError = 3, // Error determining update state.
107-
// BNCUpdateStateReinstall = 4 // App was re-installed.
103+
// Deprecated states, however older SDKs still send them. The server will ignores these values.
104+
// BNCUpdateStateInstall = 0, // App was recently installed.
105+
// BNCUpdateStateNonUpdate = 1, // App was neither newly installed nor updated.
106+
// BNCUpdateStateUpdate = 2, // App was recently updated.
107+
// BNCUpdateStateError = 3, // Error determining update state.
108+
// BNCUpdateStateReinstall = 4, // App was re-installed.
109+
110+
BNCUpdateStateUnknown = 0, // App update status is unknown
111+
BNCUpdateStateTuneMigration = 5 // App was migrated from Tune SDK to Branch SDK
108112
};
109113

110-
+ (NSNumber*) appUpdateState {
111-
112-
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
113-
BNCApplication *application = [BNCApplication currentApplication];
114-
NSTimeInterval first_install_time = application.firstInstallDate.timeIntervalSince1970;
115-
NSTimeInterval latest_install_time = application.currentInstallDate.timeIntervalSince1970;
116-
NSTimeInterval latest_update_time = application.currentBuildDate.timeIntervalSince1970;
117-
NSTimeInterval previous_update_time = preferenceHelper.previousAppBuildDate.timeIntervalSince1970;
118-
NSTimeInterval const kOneDay = 1.0 * 24.0 * 60.0 * 60.0;
119-
120-
BNCUpdateState update_state = 0;
121-
if (first_install_time <= 0.0 ||
122-
latest_install_time <= 0.0 ||
123-
latest_update_time <= 0.0 ||
124-
previous_update_time > latest_update_time)
125-
update_state = BNCUpdateStateNonUpdate; // Error: Send Non-update.
126-
else
127-
if ((latest_update_time - kOneDay) <= first_install_time && previous_update_time <= 0)
128-
update_state = BNCUpdateStateInstall;
129-
else
130-
if (first_install_time < latest_install_time && previous_update_time <= 0)
131-
update_state = BNCUpdateStateUpdate; // Re-install: Send Update.
132-
else
133-
if (latest_update_time > first_install_time && previous_update_time < latest_update_time)
134-
update_state = BNCUpdateStateUpdate;
135-
else
136-
update_state = BNCUpdateStateNonUpdate;
137-
114+
+ (NSNumber *)appUpdateState {
115+
BNCUpdateState update_state = BNCUpdateStateUnknown;
116+
if ([BNCTuneUtility isTuneDataPresent]) {
117+
update_state = BNCUpdateStateTuneMigration;
118+
}
138119
return @(update_state);
139120
}
140121

0 commit comments

Comments
 (0)