Skip to content

Commit b24014c

Browse files
authored
Merge branch 'staging' into revert-lifecyle-change
2 parents 3259da3 + 2f66b0a commit b24014c

File tree

30 files changed

+553
-158
lines changed

30 files changed

+553
-158
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// BNCCommerceEvent.h
3+
// BranchSDK-iOS
4+
//
5+
// Created by Edward Smith on 12/14/16.
6+
// Copyright (c) 2016 Branch Metrics. All rights reserved.
7+
//
8+
9+
10+
#import <Foundation/Foundation.h>
11+
#import "BNCServerRequest.h"
12+
13+
14+
@interface BNCProduct : NSObject
15+
@property (nonatomic, strong) NSString *sku;
16+
@property (nonatomic, strong) NSString *name;
17+
@property (nonatomic, strong) NSDecimalNumber *price;
18+
@property (nonatomic, strong) NSNumber *quantity;
19+
@property (nonatomic, strong) NSString *brand;
20+
@property (nonatomic, strong) NSString *category;
21+
@property (nonatomic, strong) NSString *variant;
22+
@end
23+
24+
25+
@interface BNCCommerceEvent : NSObject
26+
@property (nonatomic, strong) NSDecimalNumber *revenue;
27+
@property (nonatomic, strong) NSString *currency;
28+
@property (nonatomic, strong) NSString *transactionID;
29+
@property (nonatomic, strong) NSDecimalNumber *shipping;
30+
@property (nonatomic, strong) NSDecimalNumber *tax;
31+
@property (nonatomic, strong) NSString *coupon;
32+
@property (nonatomic, strong) NSString *affiliation;
33+
@property (nonatomic, strong) NSArray<BNCProduct*> *products;
34+
@end
35+
36+
37+
@interface BranchCommerceEventRequest : BNCServerRequest <NSCoding>
38+
39+
- (instancetype) initWithCommerceEvent:(BNCCommerceEvent*)commerceEvent
40+
metadata:(NSDictionary*)dictionary
41+
completion:(void (^)(NSDictionary* response, NSError* error))callBack;
42+
43+
@end
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//
2+
// BNCCommerceEvent.h
3+
// BranchSDK-iOS
4+
//
5+
// Created by Edward Smith on 12/14/16.
6+
// Copyright (c) 2016 Branch Metrics. All rights reserved.
7+
//
8+
9+
10+
#import "BNCCommerceEvent.h"
11+
#import "BranchConstants.h"
12+
13+
14+
@implementation BNCProduct
15+
16+
- (NSMutableDictionary*) dictionary {
17+
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
18+
19+
#define assign(x) \
20+
do { if (self.x) { dictionary[@#x] = self.x; } } while (0)
21+
22+
assign(sku);
23+
assign(name);
24+
assign(price);
25+
assign(quantity);
26+
assign(brand);
27+
assign(category);
28+
assign(variant);
29+
30+
#undef assign
31+
32+
return dictionary;
33+
}
34+
35+
@end
36+
37+
38+
@implementation BNCCommerceEvent : NSObject
39+
40+
- (NSDictionary*) dictionary {
41+
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
42+
43+
#define assign(x) \
44+
do { if (self.x) { dictionary[@#x] = self.x; } } while (0)
45+
46+
assign(revenue);
47+
assign(currency);
48+
assign(transactionID);
49+
assign(shipping);
50+
assign(tax);
51+
assign(coupon);
52+
assign(affiliation);
53+
54+
NSMutableArray *products = [NSMutableArray arrayWithCapacity:self.products.count];
55+
for (BNCProduct *product in self.products) {
56+
NSDictionary * d = [product dictionary];
57+
if (d) [products addObject:d];
58+
}
59+
dictionary[@"products"] = products;
60+
61+
#undef assign
62+
63+
return dictionary;
64+
}
65+
66+
@end
67+
68+
69+
#pragma mark - BranchCommerceEventRequest
70+
71+
72+
@interface BranchCommerceEventRequest ()
73+
@property (strong) NSDictionary *commerceDictionary;
74+
@property (strong) NSDictionary *metadata;
75+
@property (copy) void (^completion)(NSDictionary* response, NSError* error);
76+
@end
77+
78+
79+
@implementation BranchCommerceEventRequest
80+
81+
- (instancetype) initWithCommerceEvent:(BNCCommerceEvent*)commerceEvent
82+
metadata:(NSDictionary*)metadata
83+
completion:(void (^)(NSDictionary* response, NSError* error))completion {
84+
self = [super init];
85+
if (!self) return self;
86+
87+
if ([commerceEvent.revenue isEqualToNumber:[NSDecimalNumber numberWithDouble:0.0]]) {
88+
NSLog(@"[Branch] Warning: Sending a commerce event with zero value!!");
89+
}
90+
91+
self.commerceDictionary = [commerceEvent dictionary];
92+
self.metadata = metadata;
93+
self.completion = completion;
94+
return self;
95+
}
96+
97+
- (void)makeRequest:(BNCServerInterface *)serverInterface
98+
key:(NSString *)key callback:(BNCServerCallback)callback {
99+
100+
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
101+
102+
NSMutableDictionary *params = [NSMutableDictionary dictionary];
103+
params[BRANCH_REQUEST_KEY_ACTION] = @"purchase";
104+
params[BRANCH_REQUEST_KEY_DEVICE_FINGERPRINT_ID] = preferenceHelper.deviceFingerprintID;
105+
params[BRANCH_REQUEST_KEY_BRANCH_IDENTITY] = preferenceHelper.identityID;
106+
params[BRANCH_REQUEST_KEY_SESSION_ID] = preferenceHelper.sessionID;
107+
108+
if (self.metadata)
109+
params[@"metadata"] = self.metadata;
110+
if (self.commerceDictionary)
111+
params[@"commerce_data"] = self.commerceDictionary;
112+
113+
NSString *URL = [preferenceHelper getAPIURL:BRANCH_REQUEST_ENDPOINT_USER_COMPLETED_ACTION];
114+
[serverInterface postRequest:params
115+
url:URL
116+
key:key
117+
callback:callback];
118+
}
119+
120+
- (void)processResponse:(BNCServerResponse*)response
121+
error:(NSError*)error {
122+
123+
NSDictionary *dictionary =
124+
([response.data isKindOfClass:[NSDictionary class]])
125+
? (NSDictionary*) response.data
126+
: nil;
127+
128+
if (self.completion)
129+
self.completion(dictionary, error);
130+
}
131+
132+
133+
#pragma mark - NSCoding
134+
135+
136+
- (instancetype)initWithCoder:(NSCoder *)decoder {
137+
self = [super initWithCoder:decoder];
138+
if (!self) return self;
139+
140+
self.commerceDictionary = [decoder decodeObjectForKey:@"commerceDictionary"];
141+
self.metadata = [decoder decodeObjectForKey:@"metaData"];
142+
return self;
143+
}
144+
145+
- (void)encodeWithCoder:(NSCoder *)coder {
146+
[super encodeWithCoder:coder];
147+
[coder encodeObject:self.commerceDictionary forKey:@"commerceDictionary"];
148+
[coder encodeObject:self.metadata forKey:@"metadata"];
149+
}
150+
151+
@end

Branch-SDK/Branch-SDK/BNCConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import <Foundation/Foundation.h>
1010

11-
extern NSString * const SDK_VERSION;
11+
extern NSString * const BNC_SDK_VERSION;
1212
extern NSString * const BNC_API_BASE_URL;
1313
extern NSString * const BNC_LINK_URL;
1414
extern NSString * const BNC_API_VERSION;

Branch-SDK/Branch-SDK/BNCConfig.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "BNCConfig.h"
1010

1111
NSString * const BNC_API_BASE_URL = @"https://api.branch.io";
12+
//NSString * const BNC_API_BASE_URL = @"https://ahmed.api.beta.branch.io";
13+
1214
NSString * const BNC_API_VERSION = @"v1";
1315
NSString * const BNC_LINK_URL = @"https://bnc.lt";
14-
NSString * const SDK_VERSION = @"0.12.20";
16+
NSString * const BNC_SDK_VERSION = @"0.12.21";

Branch-SDK/Branch-SDK/BNCDeviceInfo.m

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717

1818
@interface BNCDeviceInfo()
19-
2019
@end
2120

21+
2222
@implementation BNCDeviceInfo
2323

2424
static BNCDeviceInfo *bncDeviceInfo;
@@ -83,20 +83,24 @@ - (id)init {
8383

8484
}
8585

86+
static NSString* browserUserAgentString = nil;
87+
8688
void (^setUpBrowserUserAgent)() = ^() {
87-
self.browserUserAgent = [[[UIWebView alloc]
88-
initWithFrame:CGRectZero]
89-
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
89+
browserUserAgentString =
90+
[[[UIWebView alloc]
91+
initWithFrame:CGRectZero]
92+
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
93+
self.browserUserAgent = browserUserAgentString;
9094
};
9195

92-
if (NSThread.isMainThread) {
93-
94-
setUpBrowserUserAgent();
95-
96-
} else {
97-
98-
dispatch_sync(dispatch_get_main_queue(), setUpBrowserUserAgent);
99-
96+
@synchronized (self.class) {
97+
if (browserUserAgentString) {
98+
self.browserUserAgent = browserUserAgentString;
99+
} else if (NSThread.isMainThread) {
100+
setUpBrowserUserAgent();
101+
} else {
102+
dispatch_sync(dispatch_get_main_queue(), setUpBrowserUserAgent);
103+
}
100104
}
101105

102106
return self;

Branch-SDK/Branch-SDK/BNCLinkData.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
// Copyright (c) 2015 Branch Metrics. All rights reserved.
77
//
88

9+
910
#import "BNCLinkData.h"
1011
#import "BNCEncodingUtils.h"
1112
#import "BranchConstants.h"
1213

13-
@interface BNCLinkData ()
1414

15+
@interface BNCLinkData ()
1516
@property (strong, nonatomic) NSArray *tags;
1617
@property (strong, nonatomic) NSString *alias;
1718
@property (strong, nonatomic) NSString *channel;
@@ -22,9 +23,9 @@ @interface BNCLinkData ()
2223
@property (strong, nonatomic) NSString *ignoreUAString;
2324
@property (assign, nonatomic) BranchLinkType type;
2425
@property (assign, nonatomic) NSUInteger duration;
25-
2626
@end
2727

28+
2829
@implementation BNCLinkData
2930

3031
- (id)init {

Branch-SDK/Branch-SDK/BNCServerInterface.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,12 @@ - (NSURLRequest *)preparePostRequest:(NSDictionary *)params url:(NSString *)url
228228
return request;
229229
}
230230

231-
- (NSDictionary *)prepareParamDict:(NSDictionary *)params key:(NSString *)key retryNumber:(NSInteger)retryNumber requestType:(NSString *)reqType {
231+
- (NSDictionary *)prepareParamDict:(NSDictionary *)params
232+
key:(NSString *)key
233+
retryNumber:(NSInteger)retryNumber requestType:(NSString *)reqType {
232234
NSMutableDictionary *fullParamDict = [[NSMutableDictionary alloc] init];
233235
[fullParamDict addEntriesFromDictionary:params];
234-
fullParamDict[@"sdk"] = [NSString stringWithFormat:@"ios%@", SDK_VERSION];
236+
fullParamDict[@"sdk"] = [NSString stringWithFormat:@"ios%@", BNC_SDK_VERSION];
235237

236238
// using rangeOfString instead of containsString to support devices running pre iOS 8
237239
if ([[[NSBundle mainBundle] executablePath] rangeOfString:@".appex/"].location != NSNotFound) {

Branch-SDK/Branch-SDK/BNCStrongMatchHelper.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ + (NSURL *)getUrlForCookieBasedMatchingWithBranchKey:(NSString *)branchKey
174174
}
175175

176176
[urlString appendFormat:@"&branch_key=%@", branchKey];
177-
[urlString appendFormat:@"&sdk=ios%@", SDK_VERSION];
177+
[urlString appendFormat:@"&sdk=ios%@", BNC_SDK_VERSION];
178178

179179
if (redirectUrl) {
180180
[urlString appendFormat:@"&redirect_url=%@",
@@ -240,6 +240,14 @@ - (BOOL) subclass:(Class)subclass selector:(SEL)selector {
240240
return YES;
241241
}
242242

243+
- (UIWindow*) keyWindow {
244+
Class UIApplicationClass = NSClassFromString(@"UIApplication");
245+
UIWindow *keyWindow = [UIApplicationClass sharedApplication].keyWindow;
246+
if (keyWindow) return keyWindow;
247+
// ToDo: Put different code for extensions here.
248+
return nil;
249+
}
250+
243251
- (BOOL) willLoadViewControllerWithURL:(NSURL*)matchURL {
244252
if (self.primaryWindow) return NO;
245253

@@ -271,10 +279,11 @@ - (BOOL) willLoadViewControllerWithURL:(NSURL*)matchURL {
271279
}
272280

273281
NSLog(@"Safari initializing."); // eDebug
282+
self.primaryWindow = [self keyWindow];
283+
274284
self.matchViewController = [[BNCMatchViewControllerSubclass alloc] initWithURL:matchURL];
275285
if (!self.matchViewController) return NO;
276286

277-
self.primaryWindow = [[UIApplication sharedApplication] keyWindow];
278287
self.matchViewController.delegate = self;
279288
self.matchViewController.view.frame = self.primaryWindow.bounds;
280289

0 commit comments

Comments
 (0)