Skip to content

Commit e1e3207

Browse files
committed
Merge branch 'staging' into check-fb-app-links-client-side
# Conflicts: # Branch-SDK/Branch-SDK/BNCPreferenceHelper.m
2 parents 1306115 + 6b5e460 commit e1e3207

15 files changed

+95
-11
lines changed

Branch-SDK/Branch-SDK/BNCDeviceInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
//---------Properties-------------//
1919
@property (nonatomic, strong) NSString *hardwareId;
20+
@property (nonatomic, strong) NSString *hardwareIdType;
2021
@property (nonatomic) BOOL isRealHardwareId;
22+
@property (nonatomic, strong) NSString *vendorId;
2123
@property (nonatomic, strong) NSString *brandName;
2224
@property (nonatomic, strong) NSString *modelName;
2325
@property (nonatomic, strong) NSString *osName;

Branch-SDK/Branch-SDK/BNCDeviceInfo.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ - (id)init {
3030
if (self = [super init]) {
3131
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
3232
BOOL isRealHardwareId;
33-
NSString *hardwareId = [BNCSystemObserver getUniqueHardwareId:&isRealHardwareId andIsDebug:preferenceHelper.isDebug];
33+
NSString *hardwareIdType;
34+
NSString *hardwareId = [BNCSystemObserver getUniqueHardwareId:&isRealHardwareId isDebug:preferenceHelper.isDebug andType:&hardwareIdType];
3435
if (hardwareId) {
3536
self.hardwareId = hardwareId;
3637
self.isRealHardwareId = isRealHardwareId;
38+
self.hardwareIdType = hardwareIdType;
3739
}
3840

41+
self.vendorId = [BNCSystemObserver getVendorId:preferenceHelper.isDebug];
3942
self.brandName = [BNCSystemObserver getBrand];
4043
self.modelName = [BNCSystemObserver getModel];
4144
self.osName = [BNCSystemObserver getOS];

Branch-SDK/Branch-SDK/BNCPreferenceHelper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
- (void)updateBranchViewCount:(NSString *)branchViewID;
6666
- (NSInteger)getBranchViewCount:(NSString *)branchViewID;
6767

68+
- (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value;
69+
- (NSMutableDictionary *)requestMetadataDictionary;
70+
6871
- (void)log:(NSString *)filename line:(int)line message:(NSString *)format, ...;
6972
- (void)logWarning:(NSString *)message;
7073
@end

Branch-SDK/Branch-SDK/BNCPreferenceHelper.m

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ @interface BNCPreferenceHelper ()
5050
@property (strong, nonatomic) NSMutableDictionary *persistenceDict;
5151
@property (strong, nonatomic) NSMutableDictionary *countsDictionary;
5252
@property (strong, nonatomic) NSMutableDictionary *creditsDictionary;
53+
@property (strong, nonatomic) NSMutableDictionary *requestMetadataDictionary;
5354
@property (assign, nonatomic) BOOL isUsingLiveKey;
5455

5556
@end
@@ -79,7 +80,8 @@ @implementation BNCPreferenceHelper
7980
retryInterval = _retryInterval,
8081
timeout = _timeout,
8182
lastStrongMatchDate = _lastStrongMatchDate,
82-
checkedFacebookAppLinks = _checkedFacebookAppLinks;
83+
checkedFacebookAppLinks = _checkedFacebookAppLinks,
84+
requestMetadataDictionary = _requestMetadataDictionary;
8385

8486
+ (BNCPreferenceHelper *)preferenceHelper {
8587
static BNCPreferenceHelper *preferenceHelper;
@@ -460,6 +462,25 @@ - (id)getBranchUniversalLinkDomains {
460462
return [[[NSBundle mainBundle] infoDictionary] objectForKey:BRANCH_PREFS_KEY_BRANCH_UNIVERSAL_LINK_DOMAINS];
461463
}
462464

465+
- (NSMutableDictionary *)requestMetadataDictionary {
466+
if (!_requestMetadataDictionary) {
467+
_requestMetadataDictionary = [NSMutableDictionary dictionary];
468+
}
469+
return _requestMetadataDictionary;
470+
}
471+
472+
- (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value {
473+
if (!key) {
474+
return;
475+
}
476+
if ([self.requestMetadataDictionary objectForKey:key] && !value) {
477+
[self.requestMetadataDictionary removeObjectForKey:key];
478+
}
479+
else if (value) {
480+
[self.requestMetadataDictionary setObject:value forKey:key];
481+
}
482+
}
483+
463484
#pragma mark - Credit Storage
464485

465486
- (NSMutableDictionary *)creditsDictionary {

Branch-SDK/Branch-SDK/BNCServerInterface.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
101101
NSURLRequest *retryRequest = retryHandler(retryNumber);
102102
[self genericHTTPRequest:retryRequest retryNumber:(retryNumber + 1) log:log callback:callback retryHandler:retryHandler];
103103
});
104+
105+
// Do not continue on if retrying, else the callback will be called incorrectly
106+
return;
104107
}
105108
else if (callback) {
106109
// Wrap up bad statuses w/ specific error messages
@@ -123,7 +126,7 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
123126
}
124127
dispatch_async(dispatch_get_main_queue(), ^{
125128
if (callback)
126-
callback(serverResponse, error);
129+
callback(serverResponse, error);
127130
});
128131
};
129132

@@ -214,6 +217,11 @@ - (NSDictionary *)prepareParamDict:(NSDictionary *)params key:(NSString *)key re
214217
fullParamDict[@"sdk"] = [NSString stringWithFormat:@"ios%@", SDK_VERSION];
215218
fullParamDict[@"retryNumber"] = @(retryNumber);
216219

220+
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] init];
221+
[metadata addEntriesFromDictionary:self.preferenceHelper.requestMetadataDictionary];
222+
[metadata addEntriesFromDictionary:fullParamDict[BRANCH_REQUEST_KEY_STATE]];
223+
fullParamDict[BRANCH_REQUEST_KEY_STATE] = metadata;
224+
217225
if ([key hasPrefix:@"key_"]) {
218226
fullParamDict[@"branch_key"] = key;
219227
}
@@ -248,9 +256,11 @@ - (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict {
248256

249257
if (deviceInfo.hardwareId) {
250258
dict[BRANCH_REQUEST_KEY_HARDWARE_ID] = deviceInfo.hardwareId;
259+
dict[BRANCH_REQUEST_KEY_HARDWARE_ID_TYPE] = deviceInfo.hardwareIdType;
251260
dict[BRANCH_REQUEST_KEY_IS_HARDWARE_ID_REAL] = @(deviceInfo.isRealHardwareId);
252261
}
253262

263+
[self safeSetValue:deviceInfo.vendorId forKey:BRANCH_REQUEST_KEY_IOS_VENDOR_ID onDict:dict];
254264
[self safeSetValue:deviceInfo.brandName forKey:BRANCH_REQUEST_KEY_BRAND onDict:dict];
255265
[self safeSetValue:deviceInfo.modelName forKey:BRANCH_REQUEST_KEY_MODEL onDict:dict];
256266
[self safeSetValue:deviceInfo.osName forKey:BRANCH_REQUEST_KEY_OS onDict:dict];

Branch-SDK/Branch-SDK/BNCStrongMatchHelper.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ - (void)presentSafariVCWithBranchKey:(NSString *)branchKey {
8080

8181
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
8282
BOOL isRealHardwareId;
83-
NSString *hardwareId = [BNCSystemObserver getUniqueHardwareId:&isRealHardwareId andIsDebug:preferenceHelper.isDebug];
83+
NSString *hardwareIdType;
84+
NSString *hardwareId = [BNCSystemObserver getUniqueHardwareId:&isRealHardwareId isDebug:preferenceHelper.isDebug andType:&hardwareIdType];
8485
if (!hardwareId || !isRealHardwareId) {
8586
[preferenceHelper logWarning:@"Cannot use cookie-based matching while setDebug is enabled"];
8687
self.shouldDelayInstallRequest = NO;
@@ -111,8 +112,13 @@ - (void)presentSafariVCWithBranchKey:(NSString *)branchKey {
111112

112113
Class SFSafariViewControllerClass = NSClassFromString(@"SFSafariViewController");
113114
if (SFSafariViewControllerClass) {
114-
UIViewController * safController = [[SFSafariViewControllerClass alloc] initWithURL:[NSURL URLWithString:urlString]];
115+
NSURL *strongMatchUrl = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
116+
if (!strongMatchUrl) {
117+
self.requestInProgress = NO;
118+
return;
119+
}
115120

121+
UIViewController * safController = [[SFSafariViewControllerClass alloc] initWithURL:strongMatchUrl];
116122
self.secondWindow = [[UIWindow alloc] initWithFrame:[[[[UIApplication sharedApplication] windows] firstObject] bounds]];
117123
UIViewController *windowRootController = [[UIViewController alloc] init];
118124
self.secondWindow.rootViewController = windowRootController;

Branch-SDK/Branch-SDK/BNCSystemObserver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
@interface BNCSystemObserver : NSObject
1212

13-
+ (NSString *)getUniqueHardwareId:(BOOL *)isReal andIsDebug:(BOOL)debug;
13+
+ (NSString *)getUniqueHardwareId:(BOOL *)isReal isDebug:(BOOL)debug andType:(NSString **)type;
14+
+ (NSString *)getVendorId:(BOOL)debug;
1415
+ (NSString *)getDefaultUriScheme;
1516
+ (NSString *)getAppVersion;
1617
+ (NSString *)getBundleID;

Branch-SDK/Branch-SDK/BNCSystemObserver.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@implementation BNCSystemObserver
1818

19-
+ (NSString *)getUniqueHardwareId:(BOOL *)isReal andIsDebug:(BOOL)debug {
19+
+ (NSString *)getUniqueHardwareId:(BOOL *)isReal isDebug:(BOOL)debug andType:(NSString **)type {
2020
NSString *uid = nil;
2121
*isReal = YES;
2222

@@ -27,20 +27,33 @@ + (NSString *)getUniqueHardwareId:(BOOL *)isReal andIsDebug:(BOOL)debug {
2727
SEL advertisingIdentifierSelector = NSSelectorFromString(@"advertisingIdentifier");
2828
NSUUID *uuid = ((NSUUID* (*)(id, SEL))[sharedManager methodForSelector:advertisingIdentifierSelector])(sharedManager, advertisingIdentifierSelector);
2929
uid = [uuid UUIDString];
30+
*type = @"idfa";
3031
}
3132

3233
if (!uid && NSClassFromString(@"UIDevice") && !debug) {
3334
uid = [[UIDevice currentDevice].identifierForVendor UUIDString];
35+
*type = @"vendor_id";
3436
}
3537

3638
if (!uid) {
3739
uid = [[NSUUID UUID] UUIDString];
40+
*type = @"random";
3841
*isReal = NO;
3942
}
4043

4144
return uid;
4245
}
4346

47+
+ (NSString *)getVendorId:(BOOL)debug {
48+
NSString *vendorId = nil;
49+
50+
if (!debug && NSClassFromString(@"UIDevice")) {
51+
vendorId = [[UIDevice currentDevice].identifierForVendor UUIDString];
52+
}
53+
54+
return vendorId;
55+
}
56+
4457
+ (BOOL)adTrackingSafe {
4558
Class ASIdentifierManagerClass = NSClassFromString(@"ASIdentifierManager");
4659
if (ASIdentifierManagerClass) {

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ typedef NS_ENUM(NSUInteger, BranchPromoCodeUsageType) {
428428

429429
- (void)suppressWarningLogs;
430430

431+
/**
432+
Key-value pairs to be included in the metadata on every request.
433+
434+
@param key String to be included in request metadata
435+
@param value Object to be included in request metadata
436+
*/
437+
- (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value;
438+
431439
#pragma mark - Session Item methods
432440

433441
///--------------------

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ - (void)accountForFacebookSDKPreventingAppLaunch {
267267
- (void)suppressWarningLogs {
268268
self.preferenceHelper.suppressWarningLogs = YES;
269269
}
270+
271+
- (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value {
272+
[self.preferenceHelper setRequestMetadataKey:key value:value];
273+
}
274+
270275
#pragma mark - InitSession Permutation methods
271276

272277
- (void)initSessionWithLaunchOptions:(NSDictionary *)options {

0 commit comments

Comments
 (0)