Skip to content

Commit 8da5e9a

Browse files
authored
Merge pull request #951 from BranchMetrics/INTENG-7695-check-for-tune
INTENG-7695 check for tune
2 parents 8c6797f + 41329e8 commit 8da5e9a

File tree

5 files changed

+71
-36
lines changed

5 files changed

+71
-36
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;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// BNCTuneUtility.h
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 10/4/19.
6+
// Copyright © 2019 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface BNCTuneUtility : NSObject
14+
15+
+ (BOOL)isTuneDataPresent;
16+
17+
@end
18+
19+
NS_ASSUME_NONNULL_END
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// BNCTuneUtility.m
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 10/4/19.
6+
// Copyright © 2019 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import "BNCTuneUtility.h"
10+
11+
@implementation BNCTuneUtility
12+
13+
// INTENG-7695 Tune data indicates an app upgrading from Tune SDK to Branch SDK
14+
+ (BOOL)isTuneDataPresent {
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;
25+
}
26+
27+
@end

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+
// Values 0-4 are deprecated and ignored by the server
104+
BNCUpdateStateIgnored0 = 0,
105+
BNCUpdateStateIgnored1 = 1,
106+
BNCUpdateStateIgnored2 = 2,
107+
BNCUpdateStateIgnored3 = 3,
108+
BNCUpdateStateIgnored4 = 4,
109+
110+
// App was migrated from Tune SDK to Branch SDK
111+
BNCUpdateStateTuneMigration = 5
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 = BNCUpdateStateIgnored0;
116+
if ([BNCTuneUtility isTuneDataPresent]) {
117+
update_state = BNCUpdateStateTuneMigration;
118+
}
138119
return @(update_state);
139120
}
140121

Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@
163163
54391A161BA249FA0061CB0F /* BranchCSSearchableItemAttributeSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 54391A141BA249FA0061CB0F /* BranchCSSearchableItemAttributeSet.m */; };
164164
54FF1F8E1BD1D4AE0004CE2E /* BranchUniversalObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 54FF1F8C1BD1D4AE0004CE2E /* BranchUniversalObject.m */; };
165165
54FF1F921BD1DC320004CE2E /* BranchLinkProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 54FF1F901BD1DC320004CE2E /* BranchLinkProperties.m */; };
166+
5F08461123480008005B17E6 /* BNCTuneUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F08460F23480008005B17E6 /* BNCTuneUtility.h */; };
167+
5F08461223480008005B17E6 /* BNCTuneUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F08461023480008005B17E6 /* BNCTuneUtility.m */; };
166168
5F205D05231864E800C776D1 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F205D04231864E800C776D1 /* WebKit.framework */; };
167169
5F205D062318659500C776D1 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F205D04231864E800C776D1 /* WebKit.framework */; };
168170
5F205D0823186AF700C776D1 /* BNCUserAgentCollectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F205D022318641700C776D1 /* BNCUserAgentCollectorTests.m */; };
@@ -421,6 +423,8 @@
421423
54FF1F8C1BD1D4AE0004CE2E /* BranchUniversalObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchUniversalObject.m; sourceTree = "<group>"; };
422424
54FF1F8F1BD1DC320004CE2E /* BranchLinkProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BranchLinkProperties.h; sourceTree = "<group>"; };
423425
54FF1F901BD1DC320004CE2E /* BranchLinkProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchLinkProperties.m; sourceTree = "<group>"; };
426+
5F08460F23480008005B17E6 /* BNCTuneUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCTuneUtility.h; sourceTree = "<group>"; };
427+
5F08461023480008005B17E6 /* BNCTuneUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCTuneUtility.m; sourceTree = "<group>"; };
424428
5F205D022318641700C776D1 /* BNCUserAgentCollectorTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCUserAgentCollectorTests.m; sourceTree = "<group>"; };
425429
5F205D04231864E800C776D1 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
426430
5F3D6712232C589100454FF1 /* BranchLastAttributedTouchData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BranchLastAttributedTouchData.m; sourceTree = "<group>"; };
@@ -919,6 +923,8 @@
919923
4DA577211E67B28700A43BDD /* NSString+Branch.m */,
920924
4D9607F21FBF9472008AB3C2 /* UIViewController+Branch.h */,
921925
4D9607F31FBF9473008AB3C2 /* UIViewController+Branch.m */,
926+
5F08460F23480008005B17E6 /* BNCTuneUtility.h */,
927+
5F08461023480008005B17E6 /* BNCTuneUtility.m */,
922928
);
923929
name = "Branch-SDK";
924930
path = "../Branch-SDK/Branch-SDK";
@@ -1001,6 +1007,7 @@
10011007
4DCAC82A1F426F7C00405D1D /* BranchRegisterViewRequest.h in Headers */,
10021008
5FB0AA6B231875B500A0F9EA /* BNCUserAgentCollector.h in Headers */,
10031009
4DCAC82B1F426F7C00405D1D /* BranchSetIdentityRequest.h in Headers */,
1010+
5F08461123480008005B17E6 /* BNCTuneUtility.h in Headers */,
10041011
4DCAC82C1F426F7C00405D1D /* BranchShortUrlRequest.h in Headers */,
10051012
4DCAC82D1F426F7C00405D1D /* BranchShortUrlSyncRequest.h in Headers */,
10061013
4DCAC82E1F426F7C00405D1D /* BranchSpotlightUrlRequest.h in Headers */,
@@ -1266,6 +1273,7 @@
12661273
5F3D6714232C589100454FF1 /* BranchLastAttributedTouchData.m in Sources */,
12671274
4D8EE7A61E1F0A5D00B1F450 /* BNCCommerceEvent.m in Sources */,
12681275
5F909B702332B82200A774D2 /* BranchLATDRequest.m in Sources */,
1276+
5F08461223480008005B17E6 /* BNCTuneUtility.m in Sources */,
12691277
4D130E7E1EE0C7B100A69A0A /* BranchCloseRequest.m in Sources */,
12701278
4DB328001FA10B9000ACF9B0 /* BranchDelegate.m in Sources */,
12711279
466B58591B17779C00A69EDE /* BNCPreferenceHelper.m in Sources */,

0 commit comments

Comments
 (0)