Skip to content

Commit

Permalink
Merge pull request #297 from BranchMetrics/update-ios-and-android-sdks
Browse files Browse the repository at this point in the history
update ios and android sdks
  • Loading branch information
ethanneff authored Mar 8, 2017
2 parents 16d1f5a + e31eabd commit a3b2143
Show file tree
Hide file tree
Showing 46 changed files with 808 additions and 334 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ gulp prerelease;
> **[optional]** Update [iOS SDK](https://github.com/BranchMetrics/ios-branch-deep-linking/tags) (will need to update `plugin.xml` dependencies if new iOS files)
```sh
./src/ios/dependencies/update.sh 0.12.20;
./src/scripts/npm/updateIosSdk.sh 0.13.5;
./src/scripts/npm/updateAndroidSdk.sh 2.5.9;
```

### Test
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "branch-cordova-sdk",
"description": "Branch Metrics Cordova SDK",
"main": "www/branch.js",
"version": "2.5.6",
"version": "2.5.7",
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
"repository": {
"type": "git",
Expand Down Expand Up @@ -38,7 +38,7 @@
"scripts": {
"commitmsg": "validate-commit-msg",
"precommit": "gulp prod",
"postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion'",
"postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/updateNpmVersion'",
"prerelease": "gulp prod",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
Expand Down
2 changes: 1 addition & 1 deletion plugin.template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="branch-cordova-sdk"
version="2.5.6">
version="2.5.7">

<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->

Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="branch-cordova-sdk"
version="2.5.6">
version="2.5.7">

<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->

Expand Down
Binary file not shown.
5 changes: 4 additions & 1 deletion src/branch.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// properties
'use strict'

var exec = require('cordova/exec')
var deviceVendor = window.clientInformation.vendor
var _API_CLASS = 'BranchSDK' // SDK Class

// javscript to sdk
function execute (method, params) {
params = !params ? [] : params

Expand All @@ -24,6 +25,7 @@ function executeCallback (method, callback, params) {
}, _API_CLASS, method, params)
}

// Branch prototype
var Branch = function Branch () {
this.debugMode = false
}
Expand Down Expand Up @@ -190,4 +192,5 @@ Branch.prototype.creditHistory = function () {
return execute('getCreditHistory')
}

// export
module.exports = new Branch()
7 changes: 5 additions & 2 deletions src/ios/dependencies/Branch-SDK/BNCConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

#include "BNCConfig.h"

#if defined(BNCTesting)
NSString * const BNC_API_BASE_URL = @"https://auhong.api.beta.branch.io";
#else
NSString * const BNC_API_BASE_URL = @"https://api.branch.io";
//NSString * const BNC_API_BASE_URL = @"https://ahmed.api.beta.branch.io";
#endif

NSString * const BNC_API_VERSION = @"v1";
NSString * const BNC_LINK_URL = @"https://bnc.lt";
NSString * const BNC_SDK_VERSION = @"0.12.27";
NSString * const BNC_SDK_VERSION = @"0.13.5";
2 changes: 2 additions & 0 deletions src/ios/dependencies/Branch-SDK/BNCDeviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@

//----------Methods----------------//
+ (BNCDeviceInfo *)getInstance;
+ (NSString*) userAgentString; // Warning: Has an implied lock on main thread on first call.
+ (NSString*) systemBuildVersion;

@end
115 changes: 98 additions & 17 deletions src/ios/dependencies/Branch-SDK/BNCDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <sys/sysctl.h>
#import "BNCDeviceInfo.h"
#import "BNCPreferenceHelper.h"
#import "BNCSystemObserver.h"
Expand Down Expand Up @@ -83,27 +84,107 @@ - (id)init {

}

self.browserUserAgent = [self.class userAgentString];
return self;
}

+ (NSString*) systemBuildVersion {
int mib[2] = { CTL_KERN, KERN_OSVERSION };
u_int namelen = sizeof(mib) / sizeof(mib[0]);

// Get the size for the buffer --

size_t bufferSize = 0;
sysctl(mib, namelen, NULL, &bufferSize, NULL, 0);
if (bufferSize <= 0) return nil;

u_char buildBuffer[bufferSize];
int result = sysctl(mib, namelen, buildBuffer, &bufferSize, NULL, 0);

NSString *version = nil;
if (result >= 0) {
version = [[NSString alloc]
initWithBytes:buildBuffer
length:bufferSize-1
encoding:NSUTF8StringEncoding];
}
return version;
}


+ (NSString*) userAgentString {

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

// We only get the string once per app run:

if (browserUserAgentString)
return browserUserAgentString;

// Did we cache it?

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

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

@synchronized (self.class) {
if (browserUserAgentString) {
self.browserUserAgent = browserUserAgentString;
} else if (NSThread.isMainThread) {
setUpBrowserUserAgent();
} else {
dispatch_sync(dispatch_get_main_queue(), setUpBrowserUserAgent);
}
// 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 browserUserAgentString;
}

// Different case for iOS 7.0:
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {
dispatch_sync(dispatch_get_main_queue(), ^ {
setBrowserUserAgent();
});
return browserUserAgentString;
}

return self;
// 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) {

dispatch_block_t agentBlock = dispatch_block_create_with_qos_class(
DISPATCH_BLOCK_DETACHED | DISPATCH_BLOCK_ENFORCE_QOS_CLASS,
QOS_CLASS_USER_INTERACTIVE,
0, ^ {
//NSLog(@"Will userAgent.");
setBrowserUserAgent();
//NSLog(@"Did userAgent.");
});
dispatch_async(dispatch_get_main_queue(), agentBlock);

dispatch_time_t timeoutTime = dispatch_time(DISPATCH_TIME_NOW, timeoutDelta);
#if defined(BNCTesting)
long result = dispatch_block_wait(agentBlock, timeoutTime);
NSLog(@"Wait result: %ld.", result);
#else
dispatch_block_wait(agentBlock, timeoutTime);
#endif
retries--;
}
return browserUserAgentString;
}

@end
14 changes: 9 additions & 5 deletions src/ios/dependencies/Branch-SDK/BNCLinkCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,34 @@
// Copyright (c) 2015 Branch Metrics. All rights reserved.
//


#import "BNCLinkCache.h"

@interface BNCLinkCache ()

@interface BNCLinkCache ()
@property (nonatomic, strong) NSMutableDictionary *cache;

@end


@implementation BNCLinkCache

- (id)init {
if (self = [super init]) {
self.cache = [[NSMutableDictionary alloc] init];
}

return self;
}

- (void)setObject:(NSString *)anObject forKey:(BNCLinkData *)aKey {
self.cache[@([aKey hash])] = anObject;
@synchronized (self) {
self.cache[@([aKey hash])] = anObject;
}
}

- (NSString *)objectForKey:(BNCLinkData *)aKey {
return self.cache[@([aKey hash])];
@synchronized (self) {
return self.cache[@([aKey hash])];
}
}

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

@property (strong, nonatomic) NSString *branchKey;
@property (strong, nonatomic) NSString *lastRunBranchKey;
@property (strong, nonatomic) NSDate *lastStrongMatchDate;
@property (strong, nonatomic) NSDate *lastStrongMatchDate;
@property (strong, nonatomic) NSString *appVersion;
@property (strong, nonatomic) NSString *deviceFingerprintID;
@property (strong, nonatomic) NSString *sessionID;
Expand All @@ -39,6 +39,9 @@
@property (strong, nonatomic) NSMutableDictionary *savedAnalyticsData;
@property (assign, nonatomic) NSInteger installRequestDelay;
@property (strong, nonatomic) NSDictionary *appleSearchAdDetails;
@property (strong, nonatomic) NSString *lastSystemBuildVersion;
@property (strong, nonatomic) NSString *browserUserAgentString;
@property (strong) NSString *branchAPIURL;

+ (BNCPreferenceHelper *)preferenceHelper;
+ (NSURL*) URLForBranchDirectory;
Expand Down Expand Up @@ -79,4 +82,7 @@
- (NSMutableDictionary *)getBranchAnalyticsData;
- (NSDictionary *)getContentAnalyticsManifest;
- (void)saveContentAnalyticsManifest:(NSDictionary *)cdManifest;

- (void) save; // Flushes preference queue to persistence.

@end
Loading

0 comments on commit a3b2143

Please sign in to comment.