Skip to content

Commit

Permalink
chore: updated iOS 0.12.23
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed Jan 9, 2017
1 parent 9d60e4f commit d5ce036
Show file tree
Hide file tree
Showing 17 changed files with 512 additions and 50 deletions.
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ SOFTWARE.
<header-file src="src/ios/dependencies/Fabric/Fabric.h" />

<header-file src="src/ios/dependencies/Branch-SDK/BNCCallbacks.h" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCCommerceEvent.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCCommerceEvent.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCConfig.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCConfig.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCContentDiscoveryManager.h" />
Expand Down
72 changes: 72 additions & 0 deletions src/ios/dependencies/Branch-SDK/BNCCommerceEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// BNCCommerceEvent.h
// BranchSDK-iOS
//
// Created by Edward Smith on 12/14/16.
// Copyright (c) 2016 Branch Metrics. All rights reserved.
//


#import <Foundation/Foundation.h>
#import "BNCServerRequest.h"


#pragma mark BNCProductCategory

typedef NSString*const BNCProductCategory;

extern BNCProductCategory BNCProductCategoryAnimalSupplies;
extern BNCProductCategory BNCProductCategoryApparel;
extern BNCProductCategory BNCProductCategoryArtsEntertainment;
extern BNCProductCategory BNCProductCategoryBabyToddler;
extern BNCProductCategory BNCProductCategoryBusinessIndustrial;
extern BNCProductCategory BNCProductCategoryCamerasOptics;
extern BNCProductCategory BNCProductCategoryElectronics;
extern BNCProductCategory BNCProductCategoryFoodBeverageTobacco;
extern BNCProductCategory BNCProductCategoryFurniture;
extern BNCProductCategory BNCProductCategoryHardware;
extern BNCProductCategory BNCProductCategoryHealthBeauty;
extern BNCProductCategory BNCProductCategoryHomeGarden;
extern BNCProductCategory BNCProductCategoryLuggageBags;
extern BNCProductCategory BNCProductCategoryMature;
extern BNCProductCategory BNCProductCategoryMedia;
extern BNCProductCategory BNCProductCategoryOfficeSupplies;
extern BNCProductCategory BNCProductCategoryReligious;
extern BNCProductCategory BNCProductCategorySoftware;
extern BNCProductCategory BNCProductCategorySportingGoods;
extern BNCProductCategory BNCProductCategoryToysGames;
extern BNCProductCategory BNCProductCategoryVehiclesParts;

#pragma mark - BNCProduct

@interface BNCProduct : NSObject
@property (nonatomic, strong) NSString *sku;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSDecimalNumber *price;
@property (nonatomic, strong) NSNumber *quantity;
@property (nonatomic, strong) NSString *brand;
@property (nonatomic, strong) BNCProductCategory category;
@property (nonatomic, strong) NSString *variant;
@end

#pragma mark - BNCCommerceEvent

@interface BNCCommerceEvent : NSObject
@property (nonatomic, strong) NSDecimalNumber *revenue;
@property (nonatomic, strong) NSString *currency;
@property (nonatomic, strong) NSString *transactionID;
@property (nonatomic, strong) NSDecimalNumber *shipping;
@property (nonatomic, strong) NSDecimalNumber *tax;
@property (nonatomic, strong) NSString *coupon;
@property (nonatomic, strong) NSString *affiliation;
@property (nonatomic, strong) NSArray<BNCProduct*> *products;
@end


@interface BranchCommerceEventRequest : BNCServerRequest <NSCoding>

- (instancetype) initWithCommerceEvent:(BNCCommerceEvent*)commerceEvent
metadata:(NSDictionary*)dictionary
completion:(void (^)(NSDictionary* response, NSError* error))callBack;

@end
203 changes: 203 additions & 0 deletions src/ios/dependencies/Branch-SDK/BNCCommerceEvent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
//
// BNCCommerceEvent.h
// BranchSDK-iOS
//
// Created by Edward Smith on 12/14/16.
// Copyright (c) 2016 Branch Metrics. All rights reserved.
//


#import "BNCCommerceEvent.h"
#import "BranchConstants.h"


#pragma mark BNCProductCategory

BNCProductCategory BNCProductCategoryAnimalSupplies = @"Animals & Pet Supplies";
BNCProductCategory BNCProductCategoryApparel = @"Apparel & Accessories";
BNCProductCategory BNCProductCategoryArtsEntertainment = @"Arts & Entertainment";
BNCProductCategory BNCProductCategoryBabyToddler = @"Baby & Toddler";
BNCProductCategory BNCProductCategoryBusinessIndustrial = @"Business & Industrial";
BNCProductCategory BNCProductCategoryCamerasOptics = @"Cameras & Optics";
BNCProductCategory BNCProductCategoryElectronics = @"Electronics";
BNCProductCategory BNCProductCategoryFoodBeverageTobacco = @"Food, Beverages & Tobacco";
BNCProductCategory BNCProductCategoryFurniture = @"Furniture";
BNCProductCategory BNCProductCategoryHardware = @"Hardware";
BNCProductCategory BNCProductCategoryHealthBeauty = @"Health & Beauty";
BNCProductCategory BNCProductCategoryHomeGarden = @"Home & Garden";
BNCProductCategory BNCProductCategoryLuggageBags = @"Luggage & Bags";
BNCProductCategory BNCProductCategoryMature = @"Mature";
BNCProductCategory BNCProductCategoryMedia = @"Media";
BNCProductCategory BNCProductCategoryOfficeSupplies = @"Office Supplies";
BNCProductCategory BNCProductCategoryReligious = @"Religious & Ceremonial";
BNCProductCategory BNCProductCategorySoftware = @"Software";
BNCProductCategory BNCProductCategorySportingGoods = @"Sporting Goods";
BNCProductCategory BNCProductCategoryToysGames = @"Toys & Games";
BNCProductCategory BNCProductCategoryVehiclesParts = @"Vehicles & Parts";

#pragma mark - BNCProduct

@implementation BNCProduct

- (NSMutableDictionary*) dictionary {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];

#define assign(x) \
do { if (self.x) { dictionary[@#x] = self.x; } } while (0)

assign(sku);
assign(name);
assign(price);
assign(quantity);
assign(brand);
assign(category);
assign(variant);

#undef assign

return dictionary;
}

- (NSString*) description {
return [NSString stringWithFormat:
@"Name: %@ Sku: %@ Price: %@ Quantity: %@ Brand: %@ Category: %@ Variant: %@",
self.name,
self.sku,
self.price,
self.quantity,
self.brand,
self.category,
self.variant];
}

@end

#pragma mark - BNCCommerceEvent

@implementation BNCCommerceEvent : NSObject

- (NSDictionary*) dictionary {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];

#define assign(x) \
do { if (self.x) { dictionary[@#x] = self.x; } } while (0)

assign(revenue);
assign(currency);
assign(transactionID);
assign(shipping);
assign(tax);
assign(coupon);
assign(affiliation);

NSMutableArray *products = [NSMutableArray arrayWithCapacity:self.products.count];
for (BNCProduct *product in self.products) {
NSDictionary * d = [product dictionary];
if (d) [products addObject:d];
}
dictionary[@"products"] = products;

#undef assign

return dictionary;
}

- (NSString*) description {
return [NSString stringWithFormat:
@"Revenue: %@ Currency: %@ TxID: %@ Shipping: %@ Tax: %@ Coupon: %@ Affl: %@ Products: %lu",
self.revenue,
self.currency,
self.transactionID,
self.shipping,
self.tax,
self.coupon,
self.affiliation,
(unsigned long) self.products.count];
}

@end


#pragma mark - BranchCommerceEventRequest


@interface BranchCommerceEventRequest ()
@property (strong) NSDictionary *commerceDictionary;
@property (strong) NSDictionary *metadata;
@property (copy) void (^completion)(NSDictionary* response, NSError* error);
@end


@implementation BranchCommerceEventRequest

- (instancetype) initWithCommerceEvent:(BNCCommerceEvent*)commerceEvent
metadata:(NSDictionary*)metadata
completion:(void (^)(NSDictionary* response, NSError* error))completion {
self = [super init];
if (!self) return self;

if ([commerceEvent.revenue isEqualToNumber:[NSDecimalNumber numberWithDouble:0.0]]) {
NSLog(@"[Branch] Warning: Sending a commerce event with zero value!!");
}

self.commerceDictionary = [commerceEvent dictionary];
self.metadata = metadata;
self.completion = completion;
return self;
}

- (void)makeRequest:(BNCServerInterface *)serverInterface
key:(NSString *)key callback:(BNCServerCallback)callback {

BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];

NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[BRANCH_REQUEST_KEY_ACTION] = @"purchase";
params[BRANCH_REQUEST_KEY_DEVICE_FINGERPRINT_ID] = preferenceHelper.deviceFingerprintID;
params[BRANCH_REQUEST_KEY_BRANCH_IDENTITY] = preferenceHelper.identityID;
params[BRANCH_REQUEST_KEY_SESSION_ID] = preferenceHelper.sessionID;

if (self.metadata)
params[@"metadata"] = self.metadata;
if (self.commerceDictionary)
params[@"commerce_data"] = self.commerceDictionary;

NSString *URL = [preferenceHelper getAPIURL:BRANCH_REQUEST_ENDPOINT_USER_COMPLETED_ACTION];
[serverInterface postRequest:params
url:URL
key:key
callback:callback];
}

- (void)processResponse:(BNCServerResponse*)response
error:(NSError*)error {

NSDictionary *dictionary =
([response.data isKindOfClass:[NSDictionary class]])
? (NSDictionary*) response.data
: nil;

if (self.completion)
self.completion(dictionary, error);
}


#pragma mark BranchCommerceEventRequest NSCoding


- (instancetype)initWithCoder:(NSCoder *)decoder {
self = [super initWithCoder:decoder];
if (!self) return self;

self.commerceDictionary = [decoder decodeObjectForKey:@"commerceDictionary"];
self.metadata = [decoder decodeObjectForKey:@"metaData"];
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder:coder];
[coder encodeObject:self.commerceDictionary forKey:@"commerceDictionary"];
[coder encodeObject:self.metadata forKey:@"metadata"];
}

@end
2 changes: 1 addition & 1 deletion src/ios/dependencies/Branch-SDK/BNCConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

extern NSString * const SDK_VERSION;
extern NSString * const BNC_SDK_VERSION;
extern NSString * const BNC_API_BASE_URL;
extern NSString * const BNC_LINK_URL;
extern NSString * const BNC_API_VERSION;
4 changes: 3 additions & 1 deletion src/ios/dependencies/Branch-SDK/BNCConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "BNCConfig.h"

NSString * const BNC_API_BASE_URL = @"https://api.branch.io";
//NSString * const BNC_API_BASE_URL = @"https://ahmed.api.beta.branch.io";

NSString * const BNC_API_VERSION = @"v1";
NSString * const BNC_LINK_URL = @"https://bnc.lt";
NSString * const SDK_VERSION = @"0.12.20";
NSString * const BNC_SDK_VERSION = @"0.12.23";
28 changes: 16 additions & 12 deletions src/ios/dependencies/Branch-SDK/BNCDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@


@interface BNCDeviceInfo()

@end


@implementation BNCDeviceInfo

static BNCDeviceInfo *bncDeviceInfo;
Expand Down Expand Up @@ -83,20 +83,24 @@ - (id)init {

}

static NSString* browserUserAgentString = nil;

void (^setUpBrowserUserAgent)() = ^() {
self.browserUserAgent = [[[UIWebView alloc]
initWithFrame:CGRectZero]
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
browserUserAgentString =
[[[UIWebView alloc]
initWithFrame:CGRectZero]
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
self.browserUserAgent = browserUserAgentString;
};

if (NSThread.isMainThread) {

setUpBrowserUserAgent();

} else {

dispatch_sync(dispatch_get_main_queue(), setUpBrowserUserAgent);

@synchronized (self.class) {
if (browserUserAgentString) {
self.browserUserAgent = browserUserAgentString;
} else if (NSThread.isMainThread) {
setUpBrowserUserAgent();
} else {
dispatch_sync(dispatch_get_main_queue(), setUpBrowserUserAgent);
}
}

return self;
Expand Down
5 changes: 3 additions & 2 deletions src/ios/dependencies/Branch-SDK/BNCLinkData.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
// Copyright (c) 2015 Branch Metrics. All rights reserved.
//


#import "BNCLinkData.h"
#import "BNCEncodingUtils.h"
#import "BranchConstants.h"

@interface BNCLinkData ()

@interface BNCLinkData ()
@property (strong, nonatomic) NSArray *tags;
@property (strong, nonatomic) NSString *alias;
@property (strong, nonatomic) NSString *channel;
Expand All @@ -22,9 +23,9 @@ @interface BNCLinkData ()
@property (strong, nonatomic) NSString *ignoreUAString;
@property (assign, nonatomic) BranchLinkType type;
@property (assign, nonatomic) NSUInteger duration;

@end


@implementation BNCLinkData

- (id)init {
Expand Down
6 changes: 4 additions & 2 deletions src/ios/dependencies/Branch-SDK/BNCServerInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,12 @@ - (NSURLRequest *)preparePostRequest:(NSDictionary *)params url:(NSString *)url
return request;
}

- (NSDictionary *)prepareParamDict:(NSDictionary *)params key:(NSString *)key retryNumber:(NSInteger)retryNumber requestType:(NSString *)reqType {
- (NSDictionary *)prepareParamDict:(NSDictionary *)params
key:(NSString *)key
retryNumber:(NSInteger)retryNumber requestType:(NSString *)reqType {
NSMutableDictionary *fullParamDict = [[NSMutableDictionary alloc] init];
[fullParamDict addEntriesFromDictionary:params];
fullParamDict[@"sdk"] = [NSString stringWithFormat:@"ios%@", SDK_VERSION];
fullParamDict[@"sdk"] = [NSString stringWithFormat:@"ios%@", BNC_SDK_VERSION];

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

0 comments on commit d5ce036

Please sign in to comment.