Skip to content

Commit bbb0ebb

Browse files
author
David Westgate
committed
Resolved merge conflict
2 parents 146b9b9 + 05745b2 commit bbb0ebb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+109
-2260
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ carthage-files/Carthage
44
*.xcuserstate
55
*.xcuserdatad
66
*.DS_Store
7-
7+
*.xcscmblueprint

Branch-SDK/Branch-SDK/BNCConfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef Branch_SDK_Config_h
1010
#define Branch_SDK_Config_h
1111

12-
#define SDK_VERSION @"0.12.3"
12+
#define SDK_VERSION @"0.12.4"
1313

1414
#define BNC_PROD_ENV
1515
//#define BNC_STAGE_ENV
@@ -20,7 +20,7 @@
2020
#endif
2121

2222
#ifdef BNC_STAGE_ENV
23-
#define BNC_API_BASE_URL @"http://api.dev.branchmetrics.io"
23+
#define BNC_API_BASE_URL @"http://api.dev.branch.io"
2424
#endif
2525

2626
#define BNC_LINK_URL @"https://bnc.lt"

Branch-SDK/Branch-SDK/BNCError.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ FOUNDATION_EXPORT NSString * const BNCErrorDomain;
1313
enum {
1414
BNCInitError = 1000,
1515
BNCDuplicateResourceError,
16-
BNCInvalidPromoCodeError,
1716
BNCRedeemCreditsError,
1817
BNCBadRequestError,
1918
BNCServerProblemError,

Branch-SDK/Branch-SDK/BNCPreferenceHelper.h

Lines changed: 6 additions & 8 deletions
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;
@@ -28,8 +27,6 @@
2827
@property (strong, nonatomic) NSString *userIdentity;
2928
@property (strong, nonatomic) NSString *sessionParams;
3029
@property (strong, nonatomic) NSString *installParams;
31-
@property (assign, nonatomic) BOOL explicitlyRequestedReferrable;
32-
@property (assign, nonatomic) BOOL isReferrable;
3330
@property (assign, nonatomic) BOOL isDebug;
3431
@property (assign, nonatomic) BOOL shouldWaitForInit;
3532
@property (assign, nonatomic) BOOL suppressWarningLogs;
@@ -43,6 +40,8 @@
4340

4441
- (NSString *)getAPIBaseURL;
4542
- (NSString *)getAPIURL:(NSString *)endpoint;
43+
- (NSString *)getEndpointFromURL:(NSString *)url;
44+
4645
- (NSString *)getBranchKey:(BOOL)isLive;
4746

4847
- (void)clearUserCreditsAndCounts;
@@ -57,17 +56,16 @@
5756
- (NSInteger)getCreditCount;
5857
- (NSInteger)getCreditCountForBucket:(NSString *)bucket;
5958

60-
- (void)setActionTotalCount:(NSString *)action withCount:(NSInteger)count;
61-
- (void)setActionUniqueCount:(NSString *)action withCount:(NSInteger)count;
62-
- (NSInteger)getActionTotalCount:(NSString *)action;
63-
- (NSInteger)getActionUniqueCount:(NSString *)action;
64-
6559
- (void)updateBranchViewCount:(NSString *)branchViewID;
6660
- (NSInteger)getBranchViewCount:(NSString *)branchViewID;
6761

6862
- (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value;
6963
- (NSMutableDictionary *)requestMetadataDictionary;
7064

65+
- (void)addInstrumentationDictionaryKey:(NSString *)key value:(NSString *)value;
66+
- (NSMutableDictionary *)instrumentationDictionary;
67+
- (void)clearInstrumentationDictionary;
68+
7169
- (void)log:(NSString *)filename line:(int)line message:(NSString *)format, ...;
7270
- (void)logWarning:(NSString *)message;
7371
@end

Branch-SDK/Branch-SDK/BNCPreferenceHelper.m

Lines changed: 27 additions & 82 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";
@@ -33,17 +32,12 @@
3332
NSString * const BRANCH_PREFS_KEY_SESSION_PARAMS = @"bnc_session_params";
3433
NSString * const BRANCH_PREFS_KEY_INSTALL_PARAMS = @"bnc_install_params";
3534
NSString * const BRANCH_PREFS_KEY_USER_URL = @"bnc_user_url";
36-
NSString * const BRANCH_PREFS_KEY_IS_REFERRABLE = @"bnc_is_referrable";
3735
NSString * const BRANCH_PREFS_KEY_BRANCH_UNIVERSAL_LINK_DOMAINS = @"branch_universal_link_domains";
3836
NSString * const BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI = @"external_intent_uri";
3937

4038
NSString * const BRANCH_PREFS_KEY_CREDITS = @"bnc_credits";
4139
NSString * const BRANCH_PREFS_KEY_CREDIT_BASE = @"bnc_credit_base_";
4240

43-
NSString * const BRANCH_PREFS_KEY_COUNTS = @"bnc_counts";
44-
NSString * const BRANCH_PREFS_KEY_TOTAL_BASE = @"bnc_total_base_";
45-
NSString * const BRANCH_PREFS_KEY_UNIQUE_BASE = @"bnc_unique_base_";
46-
4741
NSString * const BRANCH_PREFS_KEY_BRANCH_VIEW_USAGE_CNT = @"bnc_branch_view_usage_cnt_";
4842

4943
// The name of this key was specified in the account-creation API integration
@@ -52,17 +46,16 @@
5246
@interface BNCPreferenceHelper ()
5347

5448
@property (strong, nonatomic) NSMutableDictionary *persistenceDict;
55-
@property (strong, nonatomic) NSMutableDictionary *countsDictionary;
5649
@property (strong, nonatomic) NSMutableDictionary *creditsDictionary;
5750
@property (strong, nonatomic) NSMutableDictionary *requestMetadataDictionary;
51+
@property (strong, nonatomic) NSMutableDictionary *instrumentationDictionary;
5852
@property (assign, nonatomic) BOOL isUsingLiveKey;
5953

6054
@end
6155

6256
@implementation BNCPreferenceHelper
6357

6458
@synthesize branchKey = _branchKey,
65-
appKey = _appKey,
6659
lastRunBranchKey = _lastRunBranchKey,
6760
appVersion = _appVersion,
6861
deviceFingerprintID = _deviceFingerprintID,
@@ -76,7 +69,6 @@ @implementation BNCPreferenceHelper
7669
installParams = _installParams,
7770
universalLinkUrl = _universalLinkUrl,
7871
externalIntentURI = _externalIntentURI,
79-
isReferrable = _isReferrable,
8072
isDebug = _isDebug,
8173
shouldWaitForInit = _shouldWaitForInit,
8274
suppressWarningLogs = _suppressWarningLogs,
@@ -85,7 +77,8 @@ @implementation BNCPreferenceHelper
8577
timeout = _timeout,
8678
lastStrongMatchDate = _lastStrongMatchDate,
8779
checkedFacebookAppLinks = _checkedFacebookAppLinks,
88-
requestMetadataDictionary = _requestMetadataDictionary;
80+
requestMetadataDictionary = _requestMetadataDictionary,
81+
instrumentationDictionary = _instrumentationDictionary;
8982

9083
+ (BNCPreferenceHelper *)preferenceHelper {
9184
static BNCPreferenceHelper *preferenceHelper;
@@ -106,8 +99,6 @@ - (id)init {
10699

107100
_isDebug = NO;
108101
_suppressWarningLogs = NO;
109-
_explicitlyRequestedReferrable = NO;
110-
_isReferrable = [self readBoolFromDefaults:BRANCH_PREFS_KEY_IS_REFERRABLE];
111102
}
112103

113104
return self;
@@ -162,24 +153,11 @@ - (NSString *)getAPIURL:(NSString *) endpoint {
162153
return [[self getAPIBaseURL] stringByAppendingString:endpoint];
163154
}
164155

165-
#pragma mark - Preference Storage
166-
167-
- (NSString *)appKey {
168-
if (!_appKey) {
169-
_appKey = [[[NSBundle mainBundle] infoDictionary] objectForKey:BRANCH_PREFS_KEY_APP_KEY];
170-
}
171-
172-
return _appKey;
173-
}
174-
175-
- (void)setAppKey:(NSString *)appKey {
176-
NSLog(@"Usage of App Key is deprecated, please move toward using a Branch key");
177-
178-
if (![_appKey isEqualToString:appKey]) {
179-
_appKey = appKey;
180-
[self writeObjectToDefaults:BRANCH_PREFS_KEY_APP_KEY value:appKey];
181-
}
156+
- (NSString *)getEndpointFromURL:(NSString *)url {
157+
NSUInteger index = BNC_API_BASE_URL.length;
158+
return [url substringFromIndex:index];
182159
}
160+
#pragma mark - Preference Storage
183161

184162
- (NSString *)getBranchKey:(BOOL)isLive {
185163
// Already loaded a key, and it's the same state (live/test)
@@ -448,29 +426,8 @@ - (void)setCheckedFacebookAppLinks:(BOOL)checked {
448426
[self writeBoolToDefaults:BRANCH_PREFS_KEY_CHECKED_FACEBOOK_APP_LINKS value:checked];
449427
}
450428

451-
- (BOOL)isReferrable {
452-
BOOL hasIdentity = self.identityID != nil;
453-
454-
// If referrable is set, but they already have an identity, they should only
455-
// still be referrable if the dev has explicitly set always referrable.
456-
if (_isReferrable && hasIdentity) {
457-
return _explicitlyRequestedReferrable;
458-
}
459-
460-
// If not referrable, or no identity yet, whatever isReferrable has is fine to return.
461-
return _isReferrable;
462-
}
463-
464-
- (void)setIsReferrable:(BOOL)isReferrable {
465-
if (_isReferrable != isReferrable) {
466-
_isReferrable = isReferrable;
467-
[self writeBoolToDefaults:BRANCH_PREFS_KEY_IS_REFERRABLE value:isReferrable];
468-
}
469-
}
470-
471429
- (void)clearUserCreditsAndCounts {
472430
self.creditsDictionary = [[NSMutableDictionary alloc] init];
473-
self.countsDictionary = [[NSMutableDictionary alloc] init];
474431
}
475432

476433
- (id)getBranchUniversalLinkDomains {
@@ -496,6 +453,26 @@ - (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value {
496453
}
497454
}
498455

456+
- (NSMutableDictionary *)instrumentationDictionary {
457+
if (!_instrumentationDictionary) {
458+
_instrumentationDictionary = [NSMutableDictionary dictionary];
459+
}
460+
return _instrumentationDictionary;
461+
}
462+
463+
- (void)addInstrumentationDictionaryKey:(NSString *)key value:(NSString *)value {
464+
if (key && value) {
465+
[self.instrumentationDictionary setObject:value forKey:key];
466+
}
467+
}
468+
469+
- (void)clearInstrumentationDictionary {
470+
NSArray *keys = [_instrumentationDictionary allKeys];
471+
for (int i = 0 ; i < [keys count]; i++) {
472+
[_instrumentationDictionary removeObjectForKey:keys[i]];
473+
}
474+
}
475+
499476
#pragma mark - Credit Storage
500477

501478
- (NSMutableDictionary *)creditsDictionary {
@@ -552,38 +529,6 @@ - (void)clearUserCredits {
552529

553530
#pragma mark - Count Storage
554531

555-
- (NSMutableDictionary *)countsDictionary {
556-
if (!_countsDictionary) {
557-
_countsDictionary = [[self readObjectFromDefaults:BRANCH_PREFS_KEY_COUNTS] mutableCopy];
558-
559-
if (!_countsDictionary) {
560-
_countsDictionary = [[NSMutableDictionary alloc] init];
561-
}
562-
}
563-
564-
return _countsDictionary;
565-
}
566-
567-
- (void)setActionTotalCount:(NSString *)action withCount:(NSInteger)count {
568-
self.countsDictionary[[BRANCH_PREFS_KEY_TOTAL_BASE stringByAppendingString:action]] = @(count);
569-
570-
[self writeObjectToDefaults:BRANCH_PREFS_KEY_COUNTS value:self.countsDictionary];
571-
}
572-
573-
- (void)setActionUniqueCount:(NSString *)action withCount:(NSInteger)count {
574-
self.countsDictionary[[BRANCH_PREFS_KEY_UNIQUE_BASE stringByAppendingString:action]] = @(count);
575-
576-
[self writeObjectToDefaults:BRANCH_PREFS_KEY_COUNTS value:self.countsDictionary];
577-
}
578-
579-
- (NSInteger)getActionTotalCount:(NSString *)action {
580-
return [self.countsDictionary[[BRANCH_PREFS_KEY_TOTAL_BASE stringByAppendingString:action]] integerValue];
581-
}
582-
583-
- (NSInteger)getActionUniqueCount:(NSString *)action {
584-
return [self.countsDictionary[[BRANCH_PREFS_KEY_UNIQUE_BASE stringByAppendingString:action]] integerValue];
585-
}
586-
587532
- (void)updateBranchViewCount:(NSString *)branchViewID {
588533
NSInteger currentCount = [self getBranchViewCount:branchViewID] + 1;
589534
[self writeObjectToDefaults:[BRANCH_PREFS_KEY_BRANCH_VIEW_USAGE_CNT stringByAppendingString:branchViewID] value:@(currentCount)];

Branch-SDK/Branch-SDK/BNCServerInterface.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
typedef void (^BNCServerCallback)(BNCServerResponse *response, NSError *error);
1414

15-
static NSString *REQ_TAG_DEBUG_CONNECT = @"t_debug_connect";
16-
static NSString *REQ_TAG_DEBUG_LOG = @"t_debug_log";
17-
static NSString *REQ_TAG_DEBUG_SCREEN = @"t_debug_screen";
18-
static NSString *REQ_TAG_DEBUG_DISCONNECT = @"t_debug_disconnect";
19-
2015
@interface BNCServerInterface : NSObject
2116

2217
@property (strong, nonatomic) BNCPreferenceHelper *preferenceHelper;

Branch-SDK/Branch-SDK/BNCServerInterface.m

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#import "BranchConstants.h"
1414
#import "BNCDeviceInfo.h"
1515

16+
NSDate *startTime;
17+
NSString *requestEndpoint;
18+
1619
void (^NSURLSessionCompletionHandler) (NSData *data, NSURLResponse *response, NSError *error);
1720
void (^NSURLConnectionCompletionHandler) (NSURLResponse *response, NSData *responseData, NSError *error);
1821

@@ -59,6 +62,10 @@ - (void)postRequest:(NSDictionary *)post url:(NSString *)url key:(NSString *)key
5962
- (void)postRequest:(NSDictionary *)post url:(NSString *)url retryNumber:(NSInteger)retryNumber key:(NSString *)key log:(BOOL)log callback:(BNCServerCallback)callback {
6063
NSDictionary *extendedParams = [self updateDeviceInfoToParams:post];
6164
NSURLRequest *request = [self preparePostRequest:extendedParams url:url key:key retryNumber:retryNumber log:log];
65+
66+
// Instrumentation metrics
67+
requestEndpoint = [self.preferenceHelper getEndpointFromURL:url];
68+
startTime = [NSDate date];
6269

6370
[self genericHTTPRequest:request retryNumber:retryNumber log:log callback:callback retryHandler:^NSURLRequest *(NSInteger lastRetryNumber) {
6471
return [self preparePostRequest:post url:url key:key retryNumber:++lastRetryNumber log:log];
@@ -118,7 +125,11 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
118125
error = [NSError errorWithDomain:BNCErrorDomain code:BNCDuplicateResourceError userInfo:@{ NSLocalizedDescriptionKey: @"A resource with this identifier already exists" }];
119126
}
120127
else if (status >= 400) {
121-
NSString *errorString = [serverResponse.data objectForKey:@"error"] ?: @"The request was invalid.";
128+
NSString *errorString = @"The request was invalid.";
129+
130+
if ([serverResponse.data objectForKey:@"error"] && [[serverResponse.data objectForKey:@"error"] isKindOfClass:[NSString class]]) {
131+
errorString = [serverResponse.data objectForKey:@"error"];
132+
}
122133

123134
error = [NSError errorWithDomain:BNCErrorDomain code:BNCBadRequestError userInfo:@{ NSLocalizedDescriptionKey: errorString }];
124135
}
@@ -220,19 +231,16 @@ - (NSDictionary *)prepareParamDict:(NSDictionary *)params key:(NSString *)key re
220231
[fullParamDict addEntriesFromDictionary:params];
221232
fullParamDict[@"sdk"] = [NSString stringWithFormat:@"ios%@", SDK_VERSION];
222233
fullParamDict[@"retryNumber"] = @(retryNumber);
223-
234+
fullParamDict[@"branch_key"] = key;
235+
224236
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] init];
225237
[metadata addEntriesFromDictionary:self.preferenceHelper.requestMetadataDictionary];
226238
[metadata addEntriesFromDictionary:fullParamDict[BRANCH_REQUEST_KEY_STATE]];
227239
fullParamDict[BRANCH_REQUEST_KEY_STATE] = metadata;
228-
229-
if ([key hasPrefix:@"key_"]) {
230-
fullParamDict[@"branch_key"] = key;
231-
}
232-
else {
233-
fullParamDict[@"app_id"] = key;
240+
if (self.preferenceHelper.instrumentationDictionary.count) {
241+
fullParamDict[BRANCH_REQUEST_KEY_INSTRUMENTATION] = self.preferenceHelper.instrumentationDictionary;
234242
}
235-
243+
236244
return fullParamDict;
237245
}
238246

@@ -252,9 +260,18 @@ - (BNCServerResponse *)processServerResponse:(NSURLResponse *)response data:(NSD
252260
[self.preferenceHelper log:FILE_NAME line:LINE_NUM message:@"returned = %@", serverResponse];
253261
}
254262

263+
[self collectInstrumentationMetrics];
255264
return serverResponse;
256265
}
257266

267+
- (void) collectInstrumentationMetrics {
268+
// multiplying by negative because startTime happened in the past
269+
NSTimeInterval elapsedTime = [startTime timeIntervalSinceNow] * -1000.0;
270+
NSString *lastRoundTripTime = [[NSNumber numberWithDouble:floor(elapsedTime)] stringValue];
271+
NSString * brttKey = [NSString stringWithFormat:@"%@-brtt", requestEndpoint];
272+
[self.preferenceHelper clearInstrumentationDictionary];
273+
[self.preferenceHelper addInstrumentationDictionaryKey:brttKey value:lastRoundTripTime];
274+
}
258275
- (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict {
259276
BNCDeviceInfo *deviceInfo = [BNCDeviceInfo getInstance];
260277

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/BNCSystemObserver.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ + (NSString *)getUniqueHardwareId:(BOOL *)isReal isDebug:(BOOL)debug andType:(NS
2727
SEL advertisingIdentifierSelector = NSSelectorFromString(@"advertisingIdentifier");
2828
NSUUID *uuid = ((NSUUID* (*)(id, SEL))[sharedManager methodForSelector:advertisingIdentifierSelector])(sharedManager, advertisingIdentifierSelector);
2929
uid = [uuid UUIDString];
30+
// limit ad tracking is enabled. iOS 10+
31+
if ([uid isEqualToString:@"00000000-0000-0000-0000-000000000000"]) {
32+
uid = nil;
33+
}
3034
*type = @"idfa";
3135
}
3236

0 commit comments

Comments
 (0)