Skip to content

Commit

Permalink
fix: updated android 2.12.1 ios 0.18.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed Sep 22, 2017
1 parent 1dcdb76 commit 1866572
Show file tree
Hide file tree
Showing 16 changed files with 341 additions and 131 deletions.
Binary file removed src/android/dependencies/Branch-2.11.1.jar
Binary file not shown.
Binary file added src/android/dependencies/Branch-2.12.1.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ios/dependencies/Branch-SDK/BNCConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
NSString * const BNC_API_BASE_URL = @"https://api.branch.io";
NSString * const BNC_API_VERSION = @"v1";
NSString * const BNC_LINK_URL = @"https://bnc.lt";
NSString * const BNC_SDK_VERSION = @"0.17.9";
NSString * const BNC_SDK_VERSION = @"0.18.8";
100 changes: 56 additions & 44 deletions src/ios/dependencies/Branch-SDK/BNCDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ - (id)init {
return self;
}

- (NSString *)vendorId
{
- (NSString *)vendorId {
@synchronized (self) {
if (_vendorId) return _vendorId;

/*
* https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor
* BNCSystemObserver.getVendorId is based on UIDevice.identifierForVendor. Note from the
Expand Down Expand Up @@ -179,59 +177,71 @@ + (NSString*) systemBuildVersion {
return version;
}


+ (NSString*) userAgentString {

static NSString* browserUserAgentString = nil;
void (^setBrowserUserAgent)(void) = ^() {
if (!browserUserAgentString) {
browserUserAgentString =
[[[UIWebView alloc]
initWithFrame:CGRectZero]
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
BNCPreferenceHelper *preferences = [BNCPreferenceHelper preferenceHelper];
preferences.browserUserAgentString = browserUserAgentString;
preferences.lastSystemBuildVersion = self.systemBuildVersion;
BNCLogDebugSDK(@"userAgentString: '%@'.", browserUserAgentString);
}

static NSString* brn_browserUserAgentString = nil;

void (^setBrowserUserAgent)(void) = ^() {
@synchronized (self) {
if (!brn_browserUserAgentString) {
brn_browserUserAgentString =
[[[UIWebView alloc]
initWithFrame:CGRectZero]
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
BNCPreferenceHelper *preferences = [BNCPreferenceHelper preferenceHelper];
preferences.browserUserAgentString = brn_browserUserAgentString;
preferences.lastSystemBuildVersion = self.systemBuildVersion;
BNCLogDebugSDK(@"userAgentString: '%@'.", brn_browserUserAgentString);
}
}
};

// We only get the string once per app run:
NSString* (^browserUserAgent)(void) = ^ NSString* () {
@synchronized (self) {
return brn_browserUserAgentString;
}
};

@synchronized (self) {
// We only get the string once per app run:

if (browserUserAgentString)
return browserUserAgentString;
if (brn_browserUserAgentString)
return brn_browserUserAgentString;

// Did we cache it?
// Did we cache it?

BNCPreferenceHelper *preferences = [BNCPreferenceHelper preferenceHelper];
if (preferences.browserUserAgentString &&
preferences.lastSystemBuildVersion &&
[preferences.lastSystemBuildVersion isEqualToString:self.systemBuildVersion]) {
browserUserAgentString = [preferences.browserUserAgentString copy];
return browserUserAgentString;
}
BNCPreferenceHelper *preferences = [BNCPreferenceHelper preferenceHelper];
if (preferences.browserUserAgentString &&
preferences.lastSystemBuildVersion &&
[preferences.lastSystemBuildVersion isEqualToString:self.systemBuildVersion]) {
brn_browserUserAgentString = [preferences.browserUserAgentString copy];
return brn_browserUserAgentString;
}

// Make sure this executes on the main thread.
// Uses an implied lock through dispatch_queues: This can deadlock if mis-used!

// Make sure this executes on the main thread.
// Uses an implied lock through dispatch_queues: This can deadlock if mis-used!
if (NSThread.isMainThread) {
setBrowserUserAgent();
return brn_browserUserAgentString;
}

if (NSThread.isMainThread) {
setBrowserUserAgent();
return browserUserAgentString;
}
}

// Different case for iOS 7.0:
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {
BNCLogDebugSDK(@"Getting iOS 7 UserAgent.");
dispatch_sync(dispatch_get_main_queue(), ^ {
setBrowserUserAgent();
});
return browserUserAgentString;
BNCLogDebugSDK(@"Got iOS 7 UserAgent.");
return browserUserAgent();
}

// Wait and yield to prevent deadlock:

int retries = 10;
int64_t timeoutDelta = (dispatch_time_t)((long double)NSEC_PER_SEC * (long double)0.100);
while (!browserUserAgentString && retries > 0) {
// Wait and yield to prevent deadlock:
int retries = 10;
int64_t timeoutDelta = (dispatch_time_t)((long double)NSEC_PER_SEC * (long double)0.100);
while (!browserUserAgent() && retries > 0) {

dispatch_block_t agentBlock = dispatch_block_create_with_qos_class(
DISPATCH_BLOCK_DETACHED | DISPATCH_BLOCK_ENFORCE_QOS_CLASS,
Expand All @@ -243,11 +253,13 @@ + (NSString*) userAgentString {
});
dispatch_async(dispatch_get_main_queue(), agentBlock);

dispatch_time_t timeoutTime = dispatch_time(DISPATCH_TIME_NOW, timeoutDelta);
dispatch_time_t timeoutTime = dispatch_time(DISPATCH_TIME_NOW, timeoutDelta);
dispatch_block_wait(agentBlock, timeoutTime);
retries--;
}
return browserUserAgentString;
retries--;
}
BNCLogDebugSDK(@"Retries: %d", 10-retries);

return browserUserAgent();
}

@end
19 changes: 19 additions & 0 deletions src/ios/dependencies/Branch-SDK/BNCEncodingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

#import <Foundation/Foundation.h>

#pragma mark BNCKeyValue

@interface BNCKeyValue : NSObject

+ (BNCKeyValue*) key:(NSString*)key value:(NSString*)value;
- (NSString*) description;

@property (nonatomic, strong) NSString* key;
@property (nonatomic, strong) NSString* value;

@end

#pragma mark - BNCEncodingUtils

@interface BNCEncodingUtils : NSObject

+ (NSString *)base64EncodeStringToString:(NSString *)strData;
Expand All @@ -22,11 +36,16 @@
+ (NSString *)encodeDictionaryToJsonString:(NSDictionary *)dictionary;
+ (NSData *)encodeDictionaryToJsonData:(NSDictionary *)dictionary;

+ (NSString*) stringByPercentDecodingString:(NSString*)string;

+ (NSDictionary *)decodeJsonDataToDictionary:(NSData *)jsonData;
+ (NSDictionary *)decodeJsonStringToDictionary:(NSString *)jsonString;
+ (NSDictionary *)decodeQueryStringToDictionary:(NSString *)queryString;
+ (NSString *)encodeDictionaryToQueryString:(NSDictionary *)dictionary;

+ (NSString *) hexStringFromData:(NSData*)data;
+ (NSData *) dataFromHexString:(NSString*)string;

+ (NSArray<BNCKeyValue*>*) queryItems:(NSURL*)URL;

@end
79 changes: 77 additions & 2 deletions src/ios/dependencies/Branch-SDK/BNCEncodingUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@
#import "BNCLog.h"
#import <CommonCrypto/CommonDigest.h>

#pragma mark BNCKeyValue

@implementation BNCKeyValue

+ (BNCKeyValue*) key:(NSString*)key value:(NSString*)value {
BNCKeyValue *kv = [[BNCKeyValue alloc] init];
kv.key = key;
kv.value = value;
return kv;
}

- (NSString*) description {
return [NSString stringWithFormat:@"<%@, %@>", self.key, self.value];
}

- (BOOL) isEqual:(BNCKeyValue*)object {
return
[object isKindOfClass:[BNCKeyValue class]] &&
[self.key isEqualToString:object.key] &&
[self.value isEqualToString:object.value]
;
}

@end

#pragma mark - BNCEncodingUtils

@implementation BNCEncodingUtils

#pragma mark - Base 64 Encoding
Expand Down Expand Up @@ -113,8 +140,14 @@ + (NSString *)encodeDictionaryToJsonString:(NSDictionary *)dictionary {
string = NO;
}
else if ([obj isKindOfClass:[NSNumber class]]) {
value = [obj stringValue];
string = NO;
if (obj == (id)kCFBooleanFalse)
value = @"false";
else
if (obj == (id)kCFBooleanTrue)
value = @"true";
else
value = [obj stringValue];
}
else if ([obj isKindOfClass:[NSNull class]]) {
value = @"null";
Expand Down Expand Up @@ -251,7 +284,12 @@ + (NSString *)encodeDictionaryToQueryString:(NSDictionary *)dictionary {
return queryString;
}

#pragma mark - Param Decoding methods
+ (NSString*) stringByPercentDecodingString:(NSString *)string {
return [string stringByRemovingPercentEncoding];
}

#pragma mark - Param Decoding Methods

+ (NSDictionary *)decodeJsonDataToDictionary:(NSData *)jsonData {
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

Expand Down Expand Up @@ -393,4 +431,41 @@ + (NSData *) dataFromHexString:(NSString*)string {
return data;
}

#pragma mark - URL QueryItems

+ (NSArray<BNCKeyValue*>*) queryItems:(NSURL*)URL {
NSMutableArray* keyValues = [NSMutableArray new];
if (!URL) return keyValues;

NSArray *queryItems = [[URL query] componentsSeparatedByString:@"&"];
for (NSString* itemPair in queryItems) {

BNCKeyValue *keyValue = [BNCKeyValue new];
NSRange range = [itemPair rangeOfString:@"="];
if (range.location == NSNotFound) {
if (itemPair.length)
keyValue.key = itemPair;
} else {
keyValue.key = [itemPair substringWithRange:NSMakeRange(0, range.location)];
NSRange r = NSMakeRange(range.location+1, itemPair.length-range.location-1);
if (r.length > 0)
keyValue.value = [itemPair substringWithRange:r];
}

keyValue.key = [BNCEncodingUtils stringByPercentDecodingString:keyValue.key];
keyValue.key = [keyValue.key stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

keyValue.value = [BNCEncodingUtils stringByPercentDecodingString:keyValue.value];
keyValue.value = [keyValue.value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

if (keyValue.key.length || keyValue.value.length) {
if (keyValue.key == nil) keyValue.key = @"";
if (keyValue.value == nil) keyValue.value = @"";
[keyValues addObject:keyValue];
}
}

return keyValues;
}

@end
12 changes: 11 additions & 1 deletion src/ios/dependencies/Branch-SDK/BNCLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern NSString *_Nonnull const BNCLogStringFromLogLevel(BNCLogLevel level);
* @param string A string indicating the log level.
* @return Returns The log level corresponding to the string.
*/
extern BNCLogLevel BNBLogLevelFromString(NSString*_Null_unspecified string);
extern BNCLogLevel BNCLogLevelFromString(NSString*_Null_unspecified string);


#pragma mark - Programmatic Breakpoints
Expand All @@ -78,6 +78,16 @@ extern BOOL BNCLogBreakPointsAreEnabled(void);
extern void BNCLogSetBreakPointsEnabled(BOOL enabled);


#pragma mark - Client Initialization Function


typedef void (*BNCLogClientInitializeFunctionPtr)(void);

///@param clientInitializationFunction The client function that should be called before logging starts.
extern BNCLogClientInitializeFunctionPtr _Null_unspecified
BNCLogSetClientInitializeFunction(BNCLogClientInitializeFunctionPtr _Nullable clientInitializationFunction);


#pragma mark - Optional Log Output Handlers


Expand Down
24 changes: 23 additions & 1 deletion src/ios/dependencies/Branch-SDK/BNCLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ void BNCLogInternalErrorFunction(int linenumber, NSString*format, ...) {
BNCLogInternalErrorFunction(__LINE__, __VA_ARGS__)


inline static void BNCLogInitializeClient_Internal() {
BNCLogClientInitializeFunctionPtr initFunction = BNCLogSetClientInitializeFunction(NULL);
if (initFunction) {
initFunction();
}
}

#pragma mark - Default Output Functions

static int bnc_LogDescriptor = -1;
Expand Down Expand Up @@ -477,6 +484,7 @@ BNCLogLevel BNCLogDisplayLevel() {
}

void BNCLogSetDisplayLevel(BNCLogLevel level) {
BNCLogInitializeClient_Internal();
dispatch_async(bnc_LogQueue, ^{
bnc_LogDisplayLevel = level;
});
Expand All @@ -499,7 +507,7 @@ void BNCLogSetDisplayLevel(BNCLogLevel level) {
return bnc_logLevelStrings[level];
}

BNCLogLevel BNBLogLevelFromString(NSString*string) {
BNCLogLevel BNCLogLevelFromString(NSString*string) {
if (!string) return BNCLogLevelNone;
for (NSInteger i = 0; i < _countof(bnc_logLevelStrings); ++i) {
if ([bnc_logLevelStrings[i] isEqualToString:string]) {
Expand All @@ -512,6 +520,19 @@ BNCLogLevel BNBLogLevelFromString(NSString*string) {
return BNCLogLevelNone;
}

#pragma mark - Client Initialization Function

#include "stdatomic.h"
static _Atomic(BNCLogClientInitializeFunctionPtr) bnc_LogClientInitializeFunctionPtr = (BNCLogClientInitializeFunctionPtr) 0;

extern BNCLogClientInitializeFunctionPtr _Null_unspecified BNCLogSetClientInitializeFunction(
BNCLogClientInitializeFunctionPtr _Nullable clientInitializationFunction
) {
BNCLogClientInitializeFunctionPtr lastPtr =
atomic_exchange(&bnc_LogClientInitializeFunctionPtr, clientInitializationFunction);
return lastPtr;
}

#pragma mark - Break Points

static BOOL bnc_LogBreakPointsAreEnabled = NO;
Expand Down Expand Up @@ -582,6 +603,7 @@ void BNCLogWriteMessageFormat(
NSString *_Nullable message,
...
) {
BNCLogInitializeClient_Internal();
if (!file) file = "";
if (!message) message = @"<nil>";
if (![message isKindOfClass:[NSString class]]) {
Expand Down
2 changes: 1 addition & 1 deletion src/ios/dependencies/Branch-SDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ + (void) initialize {

for (NSURL *URL in URLs) {
NSError *error = nil;
NSURL *branchURL = [URL URLByAppendingPathComponent:@"io.branch" isDirectory:YES];
NSURL *branchURL = [[NSURL alloc] initWithString:@"io.branch" relativeToURL:URL];
BOOL success =
[fileManager
createDirectoryAtURL:branchURL
Expand Down
Loading

0 comments on commit 1866572

Please sign in to comment.