Skip to content

Commit a3b2143

Browse files
authored
Merge pull request #297 from BranchMetrics/update-ios-and-android-sdks
update ios and android sdks
2 parents 16d1f5a + e31eabd commit a3b2143

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+808
-334
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ gulp prerelease;
5555
> **[optional]** Update [iOS SDK](https://github.com/BranchMetrics/ios-branch-deep-linking/tags) (will need to update `plugin.xml` dependencies if new iOS files)
5656
5757
```sh
58-
./src/ios/dependencies/update.sh 0.12.20;
58+
./src/scripts/npm/updateIosSdk.sh 0.13.5;
59+
./src/scripts/npm/updateAndroidSdk.sh 2.5.9;
5960
```
6061

6162
### Test

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "branch-cordova-sdk",
33
"description": "Branch Metrics Cordova SDK",
44
"main": "www/branch.js",
5-
"version": "2.5.6",
5+
"version": "2.5.7",
66
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
77
"repository": {
88
"type": "git",
@@ -38,7 +38,7 @@
3838
"scripts": {
3939
"commitmsg": "validate-commit-msg",
4040
"precommit": "gulp prod",
41-
"postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/nodeVersion'",
41+
"postcommit": "semantic-release pre --verifyRelease='./src/scripts/npm/updateNpmVersion'",
4242
"prerelease": "gulp prod",
4343
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
4444
},

plugin.template.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.5.6">
27+
version="2.5.7">
2828

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

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2525
xmlns:android="http://schemas.android.com/apk/res/android"
2626
id="branch-cordova-sdk"
27-
version="2.5.6">
27+
version="2.5.7">
2828

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

src/branch.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// properties
12
'use strict'
2-
33
var exec = require('cordova/exec')
44
var deviceVendor = window.clientInformation.vendor
55
var _API_CLASS = 'BranchSDK' // SDK Class
66

7+
// javscript to sdk
78
function execute (method, params) {
89
params = !params ? [] : params
910

@@ -24,6 +25,7 @@ function executeCallback (method, callback, params) {
2425
}, _API_CLASS, method, params)
2526
}
2627

28+
// Branch prototype
2729
var Branch = function Branch () {
2830
this.debugMode = false
2931
}
@@ -190,4 +192,5 @@ Branch.prototype.creditHistory = function () {
190192
return execute('getCreditHistory')
191193
}
192194

195+
// export
193196
module.exports = new Branch()

src/ios/dependencies/Branch-SDK/BNCConfig.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88

99
#include "BNCConfig.h"
1010

11+
#if defined(BNCTesting)
12+
NSString * const BNC_API_BASE_URL = @"https://auhong.api.beta.branch.io";
13+
#else
1114
NSString * const BNC_API_BASE_URL = @"https://api.branch.io";
12-
//NSString * const BNC_API_BASE_URL = @"https://ahmed.api.beta.branch.io";
15+
#endif
1316

1417
NSString * const BNC_API_VERSION = @"v1";
1518
NSString * const BNC_LINK_URL = @"https://bnc.lt";
16-
NSString * const BNC_SDK_VERSION = @"0.12.27";
19+
NSString * const BNC_SDK_VERSION = @"0.13.5";

src/ios/dependencies/Branch-SDK/BNCDeviceInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@
3535

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

3941
@end

src/ios/dependencies/Branch-SDK/BNCDeviceInfo.m

Lines changed: 98 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#import <Foundation/Foundation.h>
1111
#import <UIKit/UIKit.h>
12+
#import <sys/sysctl.h>
1213
#import "BNCDeviceInfo.h"
1314
#import "BNCPreferenceHelper.h"
1415
#import "BNCSystemObserver.h"
@@ -83,27 +84,107 @@ - (id)init {
8384

8485
}
8586

87+
self.browserUserAgent = [self.class userAgentString];
88+
return self;
89+
}
90+
91+
+ (NSString*) systemBuildVersion {
92+
int mib[2] = { CTL_KERN, KERN_OSVERSION };
93+
u_int namelen = sizeof(mib) / sizeof(mib[0]);
94+
95+
// Get the size for the buffer --
96+
97+
size_t bufferSize = 0;
98+
sysctl(mib, namelen, NULL, &bufferSize, NULL, 0);
99+
if (bufferSize <= 0) return nil;
100+
101+
u_char buildBuffer[bufferSize];
102+
int result = sysctl(mib, namelen, buildBuffer, &bufferSize, NULL, 0);
103+
104+
NSString *version = nil;
105+
if (result >= 0) {
106+
version = [[NSString alloc]
107+
initWithBytes:buildBuffer
108+
length:bufferSize-1
109+
encoding:NSUTF8StringEncoding];
110+
}
111+
return version;
112+
}
113+
114+
115+
+ (NSString*) userAgentString {
116+
86117
static NSString* browserUserAgentString = nil;
118+
void (^setBrowserUserAgent)() = ^() {
119+
if (!browserUserAgentString) {
120+
browserUserAgentString =
121+
[[[UIWebView alloc]
122+
initWithFrame:CGRectZero]
123+
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
124+
BNCPreferenceHelper *preferences = [BNCPreferenceHelper preferenceHelper];
125+
preferences.browserUserAgentString = browserUserAgentString;
126+
preferences.lastSystemBuildVersion = self.systemBuildVersion;
127+
//NSLog(@"[Branch] userAgentString: '%@'.", browserUserAgentString);
128+
}
129+
};
130+
131+
// We only get the string once per app run:
132+
133+
if (browserUserAgentString)
134+
return browserUserAgentString;
135+
136+
// Did we cache it?
137+
138+
BNCPreferenceHelper *preferences = [BNCPreferenceHelper preferenceHelper];
139+
if (preferences.browserUserAgentString &&
140+
preferences.lastSystemBuildVersion &&
141+
[preferences.lastSystemBuildVersion isEqualToString:self.systemBuildVersion]) {
142+
browserUserAgentString = [preferences.browserUserAgentString copy];
143+
return browserUserAgentString;
144+
}
87145

88-
void (^setUpBrowserUserAgent)() = ^() {
89-
browserUserAgentString =
90-
[[[UIWebView alloc]
91-
initWithFrame:CGRectZero]
92-
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
93-
self.browserUserAgent = browserUserAgentString;
94-
};
95-
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-
}
146+
// Make sure this executes on the main thread.
147+
// Uses an implied lock through dispatch_queues: This can deadlock if mis-used!
148+
149+
if (NSThread.isMainThread) {
150+
setBrowserUserAgent();
151+
return browserUserAgentString;
152+
}
153+
154+
// Different case for iOS 7.0:
155+
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {
156+
dispatch_sync(dispatch_get_main_queue(), ^ {
157+
setBrowserUserAgent();
158+
});
159+
return browserUserAgentString;
104160
}
105161

106-
return self;
162+
// Wait and yield to prevent deadlock:
163+
164+
int retries = 10;
165+
int64_t timeoutDelta = (dispatch_time_t)((long double)NSEC_PER_SEC * (long double)0.100);
166+
while (!browserUserAgentString && retries > 0) {
167+
168+
dispatch_block_t agentBlock = dispatch_block_create_with_qos_class(
169+
DISPATCH_BLOCK_DETACHED | DISPATCH_BLOCK_ENFORCE_QOS_CLASS,
170+
QOS_CLASS_USER_INTERACTIVE,
171+
0, ^ {
172+
//NSLog(@"Will userAgent.");
173+
setBrowserUserAgent();
174+
//NSLog(@"Did userAgent.");
175+
});
176+
dispatch_async(dispatch_get_main_queue(), agentBlock);
177+
178+
dispatch_time_t timeoutTime = dispatch_time(DISPATCH_TIME_NOW, timeoutDelta);
179+
#if defined(BNCTesting)
180+
long result = dispatch_block_wait(agentBlock, timeoutTime);
181+
NSLog(@"Wait result: %ld.", result);
182+
#else
183+
dispatch_block_wait(agentBlock, timeoutTime);
184+
#endif
185+
retries--;
186+
}
187+
return browserUserAgentString;
107188
}
108189

109190
@end

src/ios/dependencies/Branch-SDK/BNCLinkCache.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,34 @@
66
// Copyright (c) 2015 Branch Metrics. All rights reserved.
77
//
88

9+
910
#import "BNCLinkCache.h"
1011

11-
@interface BNCLinkCache ()
1212

13+
@interface BNCLinkCache ()
1314
@property (nonatomic, strong) NSMutableDictionary *cache;
14-
1515
@end
1616

17+
1718
@implementation BNCLinkCache
1819

1920
- (id)init {
2021
if (self = [super init]) {
2122
self.cache = [[NSMutableDictionary alloc] init];
2223
}
23-
2424
return self;
2525
}
2626

2727
- (void)setObject:(NSString *)anObject forKey:(BNCLinkData *)aKey {
28-
self.cache[@([aKey hash])] = anObject;
28+
@synchronized (self) {
29+
self.cache[@([aKey hash])] = anObject;
30+
}
2931
}
3032

3133
- (NSString *)objectForKey:(BNCLinkData *)aKey {
32-
return self.cache[@([aKey hash])];
34+
@synchronized (self) {
35+
return self.cache[@([aKey hash])];
36+
}
3337
}
3438

3539
@end

0 commit comments

Comments
 (0)