Skip to content

Commit 8e1d8d9

Browse files
authored
Merge pull request #390 from BranchMetrics/bye-appkey
Bid app key farewell
2 parents 60cecae + 03ded5e commit 8e1d8d9

File tree

6 files changed

+12
-81
lines changed

6 files changed

+12
-81
lines changed

Branch-SDK/Branch-SDK/BNCPreferenceHelper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
@interface BNCPreferenceHelper : NSObject
1515

1616
@property (strong, nonatomic) NSString *branchKey;
17-
@property (strong, nonatomic) NSString *appKey;
1817
@property (strong, nonatomic) NSString *lastRunBranchKey;
1918
@property (strong, nonatomic) NSDate *lastStrongMatchDate;
2019
@property (strong, nonatomic) NSString *appVersion;

Branch-SDK/Branch-SDK/BNCPreferenceHelper.m

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
NSString * const BRANCH_PREFS_FILE = @"BNCPreferences";
2020

21-
NSString * const BRANCH_PREFS_KEY_APP_KEY = @"bnc_app_key";
2221
NSString * const BRANCH_PREFS_KEY_APP_VERSION = @"bnc_app_version";
2322
NSString * const BRANCH_PREFS_KEY_LAST_RUN_BRANCH_KEY = @"bnc_last_run_branch_key";
2423
NSString * const BRANCH_PREFS_KEY_LAST_STRONG_MATCH_DATE = @"bnc_strong_match_created_date";
@@ -57,7 +56,6 @@ @interface BNCPreferenceHelper ()
5756
@implementation BNCPreferenceHelper
5857

5958
@synthesize branchKey = _branchKey,
60-
appKey = _appKey,
6159
lastRunBranchKey = _lastRunBranchKey,
6260
appVersion = _appVersion,
6361
deviceFingerprintID = _deviceFingerprintID,
@@ -161,23 +159,6 @@ - (NSString *)getEndpointFromURL:(NSString *)url {
161159
}
162160
#pragma mark - Preference Storage
163161

164-
- (NSString *)appKey {
165-
if (!_appKey) {
166-
_appKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:BRANCH_PREFS_KEY_APP_KEY];
167-
}
168-
169-
return _appKey;
170-
}
171-
172-
- (void)setAppKey:(NSString *)appKey {
173-
NSLog(@"Usage of App Key is deprecated, please move toward using a Branch key");
174-
175-
if (![_appKey isEqualToString:appKey]) {
176-
_appKey = appKey;
177-
[self writeObjectToDefaults:BRANCH_PREFS_KEY_APP_KEY value:appKey];
178-
}
179-
}
180-
181162
- (NSString *)getBranchKey:(BOOL)isLive {
182163
// Already loaded a key, and it's the same state (live/test)
183164
if (_branchKey && isLive == self.isUsingLiveKey) {

Branch-SDK/Branch-SDK/BNCServerInterface.m

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,16 @@ - (NSDictionary *)prepareParamDict:(NSDictionary *)params key:(NSString *)key re
231231
[fullParamDict addEntriesFromDictionary:params];
232232
fullParamDict[@"sdk"] = [NSString stringWithFormat:@"ios%@", SDK_VERSION];
233233
fullParamDict[@"retryNumber"] = @(retryNumber);
234-
234+
fullParamDict[@"branch_key"] = key;
235+
235236
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] init];
236237
[metadata addEntriesFromDictionary:self.preferenceHelper.requestMetadataDictionary];
237238
[metadata addEntriesFromDictionary:fullParamDict[BRANCH_REQUEST_KEY_STATE]];
238239
fullParamDict[BRANCH_REQUEST_KEY_STATE] = metadata;
239240
if (self.preferenceHelper.instrumentationDictionary.count) {
240241
fullParamDict[BRANCH_REQUEST_KEY_INSTRUMENTATION] = self.preferenceHelper.instrumentationDictionary;
241242
}
242-
if ([key hasPrefix:@"key_"]) {
243-
fullParamDict[@"branch_key"] = key;
244-
}
245-
else {
246-
fullParamDict[@"app_id"] = key;
247-
}
248-
243+
249244
return fullParamDict;
250245
}
251246

Branch-SDK/Branch-SDK/BNCStrongMatchHelper.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,7 @@ - (void)presentSafariVCWithBranchKey:(NSString *)branchKey {
100100
}
101101

102102
if (branchKey) {
103-
if ([branchKey hasPrefix:@"key_"]) {
104-
[urlString appendFormat:@"&branch_key=%@", branchKey];
105-
}
106-
else {
107-
[urlString appendFormat:@"&app_id=%@", branchKey];
108-
}
103+
[urlString appendFormat:@"&branch_key=%@", branchKey];
109104
}
110105

111106
[urlString appendFormat:@"&sdk=ios%@", SDK_VERSION];

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,10 @@ + (Branch *)getInstance {
9797
NSString *branchKey = [preferenceHelper getBranchKey:YES];
9898
NSString *keyToUse = branchKey;
9999
if (!branchKey) {
100-
// If no app key
101-
NSString *appKey = preferenceHelper.appKey;
102-
if (!appKey) {
103-
[preferenceHelper logWarning:@"Please enter your branch_key in the plist!"];
104-
return nil;
105-
}
106-
else {
107-
keyToUse = appKey;
108-
NSLog(@"Usage of App Key is deprecated, please move toward using a Branch key");
109-
}
100+
[preferenceHelper logWarning:@"Please enter your branch_key in the plist!"];
101+
return nil;
110102
}
111-
103+
112104
return [Branch getInstanceInternal:keyToUse returnNilIfNoCurrentInstance:NO];
113105
}
114106

@@ -119,17 +111,8 @@ + (Branch *)getTestInstance {
119111
NSString *branchKey = [preferenceHelper getBranchKey:NO];
120112
NSString *keyToUse = branchKey;
121113
if (!branchKey) {
122-
// If no app key
123-
NSString *appKey = preferenceHelper.appKey;
124-
if (!appKey) {
125-
[preferenceHelper logWarning:@"Please enter your branch_key in the plist!"];
126-
return nil;
127-
}
128-
// If they did provide an app key, show them a warning. Shouldn't use app key with a test instance.
129-
else {
130-
[preferenceHelper logWarning:@"You requested the test instance, but provided an app key. App Keys cannot be used for test instances. Additionally, usage of App Key is deprecated, please move toward using a Branch key"];
131-
keyToUse = appKey;
132-
}
114+
[preferenceHelper logWarning:@"Please enter your branch_key in the plist!"];
115+
return nil;
133116
}
134117

135118
return [Branch getInstanceInternal:keyToUse returnNilIfNoCurrentInstance:NO];
@@ -138,11 +121,12 @@ + (Branch *)getTestInstance {
138121
+ (Branch *)getInstance:(NSString *)branchKey {
139122
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
140123

141-
if ([branchKey rangeOfString:@"key_"].location != NSNotFound) {
124+
if ([branchKey hasPrefix:@"key_"]) {
142125
preferenceHelper.branchKey = branchKey;
143126
}
144127
else {
145-
preferenceHelper.appKey = branchKey;
128+
[preferenceHelper logWarning:@"Invalid Branch Key format!"];
129+
return nil;
146130
}
147131

148132
return [Branch getInstanceInternal:branchKey returnNilIfNoCurrentInstance:NO];

Branch-TestBed/Branch-SDK-Tests/BNCServerInterfaceTests.m

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,6 @@ - (void)testParamAddForBranchKey {
5757

5858
}
5959

60-
//==================================================================================
61-
//TEST 02
62-
//This test checks to see that the branch key has been added to the GET request
63-
64-
- (void)testParamAddForAppKey {
65-
BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init];
66-
XCTestExpectation* expectation = [self expectationWithDescription:@"NSURLSessionDataTask completed"];
67-
68-
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
69-
// We're not sending a request, just verifying a "branch_key=key_foo" is present.
70-
XCTAssertTrue([request.URL.query rangeOfString:@"app_id=non_branch_key"].location != NSNotFound, @"Branch App ID not added");
71-
[expectation fulfill];
72-
return [request.URL.query rangeOfString:@"app_id=key_foo"].location != NSNotFound;
73-
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
74-
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
75-
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
76-
}];
77-
78-
[serverInterface getRequest:nil url:@"http://foo" key:@"non_branch_key" callback:NULL];
79-
80-
[self waitForExpectationsWithTimeout:5.0 /* 5 seconds */ handler:nil];
81-
}
82-
8360
#pragma mark - Retry tests
8461

8562
//==================================================================================

0 commit comments

Comments
 (0)