Skip to content

Commit

Permalink
Merge pull request #337 from BranchMetrics/npm-update
Browse files Browse the repository at this point in the history
fix: updated node dependencies
  • Loading branch information
ethanneff authored Jul 11, 2017
2 parents 2eaff07 + edc5480 commit e80e7e3
Show file tree
Hide file tree
Showing 16 changed files with 558 additions and 262 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ testbed/platforms
testbed/plugins
testbed/hooks
testbed/build.json
testbed/config.xml
testbed/package.json
node_modules
.installed
Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@
./testbed/init -adc
```
- files
- test `branch.js` with console logs to Safari and Chrome inspectors
- test `hooks` by changing to `before_prepare` and console logs with `cordova build`
- test `BranchSDK.m` with `NSLog()` with Xcode
- test `BranchSDK.java` with `system.out.println()` with Android Studio
## Submit
- **[required]** Git [comment prefix](https://github.com/semantic-release/semantic-release): `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`, `revert`
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@
// for development and debugging only
Branch.setDebug(true)

// sync with Mixpanel if installed
// for better Android matching
Branch.setCookieBasedMatching('cordova.app.link')

// to sync with Mixpanel if plugin is installed
Branch.setMixpanelToken('your_mixpanel_token')

// Branch initialization
Expand Down
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
android {
defaultConfig {
multiDexEnabled true
}
}

dependencies {
// multidex for frameworks
compile 'com.android.support:multidex:1.0.1'
// branch sdk
compile 'io.branch.sdk.android:library:2+'
// branch app indexing
compile 'com.google.android.gms:play-services-appindexing:9.+'
// branch chrome tabs for better matching
compile 'com.android.support:customtabs:23.3.0'
// branch gaid for better device matching
compile 'com.google.android.gms:play-services-ads:9+'
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@
"dependencies": {
"mkpath": "^1.0.0",
"node-version-compare": "^1.0.1",
"plist": "^2.0.1",
"plist": "^2.1.0",
"xml2js": "^0.4.17"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-standard": "^9.0.0",
"husky": "^0.13.2",
"gulp-standard": "^10.0.0",
"husky": "^0.13.4",
"mkpath": "^1.0.0",
"node-version-compare": "^1.0.1",
"plist": "^2.1.0",
"semantic-release": "^6.3.6",
"validate-commit-msg": "^2.11.2",
"validate-commit-msg": "^2.12.2",
"xml2js": "^0.4.17"
}
}
2 changes: 1 addition & 1 deletion plugin.template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ SOFTWARE.
</config-file>

<source-file src="src/android/io/branch/BranchSDK.java" target-dir="src/io/branch" />
<framework src="io.branch.sdk.android:library:2+" />
<framework src="build.gradle" custom="true" type="gradleReference" />
</platform>

<!-- iOS -->
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ SOFTWARE.
</config-file>

<source-file src="src/android/io/branch/BranchSDK.java" target-dir="src/io/branch" />
<framework src="io.branch.sdk.android:library:2+" />
<framework src="build.gradle" custom="true" type="gradleReference" />
</platform>

<!-- iOS -->
Expand Down
21 changes: 21 additions & 0 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,27 @@ private void generateShortUrl(int instanceIdx, JSONObject options, JSONObject co

}

/**
* <p>Sets the cookie based matching for all incoming requests.</p>
* <p>If you want cookie based matching, call this <b>before</b> initUserSession</p>
*
* @param linkDomain A {@link String} value to of the link domain for cookie based matching.
* @param callbackContext A callback to execute at the end of this method
*/
private void setCookieBasedMatching(String linkDomain, CallbackContext callbackContext)
{

this.activity = this.cordova.getActivity();

Branch instance = Branch.getAutoInstance(this.activity.getApplicationContext());

if (linkDomain != null) {
instance.enableCookieBasedMatching(linkDomain);
}

callbackContext.success("Success");
}

/**
* <p>Sets the library to function in debug mode, enabling logging of all requests.</p>
* <p>If you want to flag debug, call this <b>before</b> initUserSession</p>
Expand Down
6 changes: 6 additions & 0 deletions src/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ Branch.prototype.setDebug = function (isEnabled) {
return execute('setDebug', [isEnabled])
}

Branch.prototype.setCookieBasedMatching = function (linkDomain) {
if (linkDomain && deviceVendor.indexOf('Apple') < 0) {
return execute('setCookieBasedMatching', [linkDomain])
}
}

Branch.prototype.getFirstReferringParams = function () {
return execute('getFirstReferringParams')
}
Expand Down
12 changes: 11 additions & 1 deletion src/ios/AppDelegate+BranchSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#import <Branch/Branch.h>
#endif

@interface AppDelegate (BranchSDK)
@interface AppDelegate (BranchSdk)

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler;

Expand Down Expand Up @@ -48,4 +48,14 @@ - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserAct
return YES;
}

// Respond to Push Notifications
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
@try {
[[Branch getInstance] handlePushNotification:userInfo];
}
@catch (NSException *exception) {
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"BSDKPostUnhandledURL" object:userInfo]];
}
}

@end
9 changes: 9 additions & 0 deletions src/scripts/android/updateAndroidManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
var mainActivityIndex = getMainLaunchActivityIndex(manifest['manifest']['application'][0]['activity'])

// update manifest
manifest = updateMultidex(manifest)
manifest = updateBranchMetaData(manifest, preferences)
manifest = updateBranchReferrerTracking(manifest)
manifest = updateLaunchOptionToSingleTask(manifest, mainActivityIndex, preferences)
Expand Down Expand Up @@ -56,6 +57,14 @@
return manifest
}

// adds to <application> for multidex (needed for all the frameworks)
// <application android:name="android.support.multidex.MultiDexApplication" >
// </application>
function updateMultidex (manifest) {
manifest['manifest']['application'][0]['$']['android:name'] = 'android.support.multidex.MultiDexApplication'
return manifest
}

// adds to <application> for install referrer tracking (optional)
// <receiver android:name="io.branch.referral.InstallListener" android:exported="true">
// <intent-filter>
Expand Down
16 changes: 5 additions & 11 deletions src/scripts/npm/downloadNpmDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@
var modules = getNodeModulesToInstall(dependencies)
if (modules.length === 0) return async.promise

installNodeModules(modules, function (err) {
if (err) {
// handle error
throw new Error('BRANCH SDK: Failed to install the Branch SDK. Docs https://goo.gl/GijGKP')
} else {
// only run once
setPackageInstalled(installFlagLocation)
removeEtcDirectory()
}
installNodeModules(modules, function () {
// only run once
setPackageInstalled(installFlagLocation)
removeEtcDirectory()
async.resolve()
})

Expand All @@ -47,7 +42,7 @@
function installNodeModules (modules, callback) {
// base case
if (modules.length <= 0) {
return callback(false)
return callback()
}

// install one at a time
Expand All @@ -58,7 +53,6 @@
exec(install, function (err, stdout, stderr) {
// handle error
if (err) {
callback(true)
throw new Error('BRANCH SDK: Failed to install Branch node dependency ' + module + '. Docs https://goo.gl/GijGKP')
} else {
// next module
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions testbed/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ main() {
rm -rf ./plugins
rm -rf ./platforms
rm -rf ./build.json
rm -rf ./config.xml
rm -rf ./package.json

# config
yes | \cp -f config.template.xml config.xml

# build (platforms added before plugin because before_plugin_install does not work on file reference)
if [[ "$run_ios" == "true" ]]; then
cordova platform add ios
Expand All @@ -76,6 +80,13 @@ main() {
cordova platform add android
fi

# TODO: remove this cordova error fix (https://stackoverflow.com/questions/42350505/error-cannot-read-property-replace-of-undefined-when-building-ios-cordova)
if [[ "$run_ios" == "true" ]]; then
cd ./platforms/ios/cordova/node_modules/
npm install ios-sim@latest
cd ../../../../
fi

# plugin
cordova plugin add ../

Expand Down
3 changes: 3 additions & 0 deletions testbed/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function BranchInit (isDebug) {
// for development and debugging only
Branch.setDebug(isDebug)

// for better Android matching
Branch.setCookieBasedMatching('cordova.app.link')

// sync with Mixpanel if installed
Branch.setMixpanelToken('your_mixpanel_token')

Expand Down
Loading

0 comments on commit e80e7e3

Please sign in to comment.