diff --git a/.gitignore b/.gitignore
index e717bade..f3485004 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,5 @@ package-lock.json
npm-debug.log*
yarn-error.log*
.vscode
+.idea
+src/android/.idea
\ No newline at end of file
diff --git a/README.md b/README.md
index 9ba6029c..c8d3e153 100644
--- a/README.md
+++ b/README.md
@@ -55,6 +55,8 @@ _Questions? [Contact us](https://support.branch.io/support/tickets/new)_
* [Compiling: Updating the Branch SDK](#compiling-updating-the-branch-sdk)
* [Compiling: Incompatible Plugins](#compiling-incompatible-plugins)
* [Compiling: Errors](#compiling-errors)
+ * [Compiling: Capacitor](#compiling-capacitor)
+ * [AppStore: iOS](#appstore-ios)
## Getting Started
@@ -727,7 +729,6 @@ _Questions? [Contact us](https://support.branch.io/support/tickets/new)_
-
```
@@ -1348,3 +1349,61 @@ _Questions? [Contact us](https://support.branch.io/support/tickets/new)_
```
* Add `` to your `config.xml`
+
+ * error
+
+ ```sh
+ Branch.h not found
+ ```
+ If that is the ONLY error you see, this can be fixed by upgrading dependencies.
+ Ensure you are using version 4.0.1 of this plugin or higher and have updated your Xcode, Cordova, and other dependencies (listed below) to the latest versions. This error arose due to an inability in CocoaPods and cordova-ios to resolve dependencies that was later fixed.
+
+ Sometimes this error occurs when a build error occurs in the Pod project; since Branch is usually the first pod alphabetically, it'll show up as the error when attempting to build the main project (since the Pod didn't get built), even though the real error is elsewhere. Make sure to read your build log to find the original error that prevented building the Pod project.
+
+ * error: ios build fails with Pods and CONFIGURATION_BUILD_DIR configured
+
+ Command-line builds result in the above error. Please see the section below [Compiling: Capacitor](#compiling-capacitor) for the full list of up-to-date dependencies needed for CLI builds to work.
+
+* #### Compiling: Capacitor
+
+ * ##### Version 4.0.1 of this plugin works with Ionic 4 + Cordova and Ionic 4 + Capacitor, with the following caveats:
+
+ * We strongly recommend Node >= 10.15. Node 8 might work, but it is not tested.
+ * For BOTH Cordova and Capacitor, you must use Xcode >= 11.1, CocoaPods >= 1.8.4, Cordova >= 9.0.0, Ionic-CLI >= 5.1, cordova-ios >= 5.1.0
+ * Every single one of these dependencies has fixes that allow the command line build, and the pod dependency resolution to work correctly
+ * You MUST use @capacitor/ios >= 1.4.0. Versions prior to that version did not federate the OpenURL notifications to other plugins, including Branch.
+ * `use_frameworks` has been removed from this plugin and will now be statically built. If the other podfile uses `use_frameworks` that is fine but this plugin no longer flags itself as dynamic.
+ * When using Capacitor, you must add the following entries yourself to `ios/App/App/Info.plist`:
+ ```sh
+ CFBundleURLTypes
+
+
+ CFBundleURLName
+ com.getcapacitor.capacitor
+ CFBundleURLSchemes
+
+ capacitor
+
+
+
+ CFBundleURLName
+ branch-cordova-sdk
+ CFBundleURLSchemes
+
+ [YOUR URL SCHEME HERE]
+
+
+
+ branch_key
+ [YOUR BRANCH LIVE KEY]
+ branch_app_domain
+ [YOUR DOMAIN].app.link
+ ```
+ * When using Capacitor, you must add your Associated Domains entitlements via the Xcode entitlement editor yourself
+ * This MUST be done using Xcode - this is part of Capacitor's philosophy whereby you are in control of every config file change
+ * Open the "Signing & Entitlements" tab in Xcode, add the Associated Domains entitlement, and add the urls found on your Branch dashboard.
+
+* #### AppStore: iOS
+
+ * #### App rejected because it uses push notification features but does not declare the aps-environment key
+ When branch-cordova-sdk moved to use CocoaPods, a change was introduced in Cordova 9 where the separate entitlement files were no longer flattened together. This issue has been fixed in version 4.0.1 of this plugin.
diff --git a/package.json b/package.json
index c8fd9adf..defab6d4 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "branch-cordova-sdk",
"description": "Branch Metrics Cordova SDK",
"main": "src/index.js",
- "version": "4.0.0",
+ "version": "4.1.0",
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
"repository": {
"type": "git",
@@ -17,7 +17,7 @@
],
"license": "MIT",
"engines": [
- {
+ {
"name": "cordova",
"version": ">=9.0.0"
}
diff --git a/plugin.xml b/plugin.xml
index 2184665e..ca56879d 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -24,7 +24,7 @@ SOFTWARE.
+ version="4.1.0">
branch-cordova-sdk
@@ -36,7 +36,7 @@ SOFTWARE.
-
+
@@ -62,7 +62,7 @@ SOFTWARE.
-
+
@@ -85,8 +85,8 @@ SOFTWARE.
-
-
+
+
diff --git a/src/android/io/branch/BranchSDK.java b/src/android/io/branch/BranchSDK.java
index 95b96d6d..9c7760d4 100644
--- a/src/android/io/branch/BranchSDK.java
+++ b/src/android/io/branch/BranchSDK.java
@@ -20,6 +20,8 @@
import io.branch.indexing.BranchUniversalObject;
import io.branch.referral.Branch;
+import io.branch.referral.BranchUtil;
+import io.branch.referral.PrefHelper;
import io.branch.referral.BranchError;
import io.branch.referral.BranchViewHandler;
import io.branch.referral.SharingHelper;
@@ -31,8 +33,9 @@
import io.branch.referral.util.ProductCategory;
import io.branch.referral.util.ShareSheetStyle;
-import io.branch.referral.util.BranchCrossPlatformId;
-import io.branch.referral.util.BranchLastAttributedTouchData;
+import io.branch.referral.ServerRequestGetLATD.BranchLastAttributedTouchDataListener;
+import io.branch.referral.ServerRequestGetCPID.BranchCrossPlatformIdListener;
+import io.branch.referral.util.BranchCPID;
public class BranchSDK extends CordovaPlugin {
@@ -41,6 +44,8 @@ static class BranchLinkProperties extends io.branch.referral.util.LinkProperties
// Standard Debugging Variables
private static final String LCAT = "CordovaBranchSDK";
+ // todo pick up plugin version dynamically
+ private static final String BRANCH_PLUGIN_VERSION = "4.1.0";
// Private Method Properties
private ArrayList branchObjectWrappers;
@@ -68,17 +73,19 @@ public BranchSDK() {
protected void pluginInitialize() {
this.activity = this.cordova.getActivity();
-
Branch.disableInstantDeepLinking(true);
- Branch.getAutoInstance(this.activity.getApplicationContext());
-
+ BranchUtil.setPluginType(BranchUtil.PluginType.CordovaIonic);
+ BranchUtil.setPluginVersion(BRANCH_PLUGIN_VERSION);
+ if (this.instance == null) {
+ this.instance = Branch.getAutoInstance(this.activity.getApplicationContext());
+ }
}
/**
* Called when the activity receives a new intent.
*/
public void onNewIntent(Intent intent) {
-
+ intent.putExtra("branch_force_new_session", true);
this.activity.setIntent(intent);
this.reInitSession();
@@ -260,11 +267,15 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
}
public void crossPlatformIds(CallbackContext callbackContext) {
- this.instance.getCrossPlatformIds(new BranchCPIDListener(callbackContext));
+ // stub call from known issue with caching
+ // this.instance.getCrossPlatformIds(new BranchCPIDListener(callbackContext));
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
}
public void lastAttributedTouchData(CallbackContext callbackContext) {
- this.instance.getLastAttributedTouchData(new BranchLATDListener(callbackContext), 30);
+ // stub call from known issue with caching
+ // this.instance.getLastAttributedTouchData(new BranchLATDListener(callbackContext), 30);
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
}
//////////////////////////////////////////////////
@@ -288,7 +299,6 @@ private void initSession(CallbackContext callbackContext) {
}
this.sessionListener = new SessionListener(callbackContext);
- this.instance = Branch.getAutoInstance(this.activity.getApplicationContext());
this.instance.initSession(this.sessionListener, data, activity);
}
@@ -609,10 +619,8 @@ private void setCookieBasedMatching(String linkDomain, CallbackContext callbackC
this.activity = this.cordova.getActivity();
- Branch instance = Branch.getAutoInstance(this.activity.getApplicationContext());
-
if (linkDomain != null) {
- instance.enableCookieBasedMatching(linkDomain);
+ Branch.enableCookieBasedMatching(linkDomain);
}
callbackContext.success("Success");
@@ -627,7 +635,7 @@ private void setCookieBasedMatching(String linkDomain, CallbackContext callbackC
*/
private void setDebug(boolean isEnable, CallbackContext callbackContext) {
this.activity = this.cordova.getActivity();
- Branch.getAutoInstance(this.activity.getApplicationContext()).setDebug();
+ Branch.enableDebugMode();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, isEnable));
}
@@ -641,7 +649,8 @@ private void setDebug(boolean isEnable, CallbackContext callbackContext) {
*/
private void disableTracking(boolean isEnable, CallbackContext callbackContext) {
this.activity = this.cordova.getActivity();
- Branch.getAutoInstance(this.activity.getApplicationContext()).disableTracking(isEnable);
+
+ this.instance.disableTracking(isEnable);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, isEnable));
}
@@ -888,7 +897,7 @@ public BranchUniversalObjectWrapper(BranchUniversalObject branchUniversalObj) {
//----------- INNER CLASS LISTENERS ------------//
//////////////////////////////////////////////////
- protected class BranchCPIDListener implements BranchCrossPlatformId.BranchCrossPlatformIdListener {
+ protected class BranchCPIDListener implements BranchCrossPlatformIdListener {
private CallbackContext _callbackContext;
public BranchCPIDListener(CallbackContext callbackContext) {
@@ -896,7 +905,7 @@ public BranchCPIDListener(CallbackContext callbackContext) {
}
@Override
- public void onDataFetched(BranchCrossPlatformId.BranchCPID branchCPID, BranchError error) {
+ public void onDataFetched(BranchCPID branchCPID, BranchError error) {
if (error != null) {
Log.d(LCAT, "CPID unavailable");
this._callbackContext.error("CPID unavailable");
@@ -921,7 +930,7 @@ public void onDataFetched(BranchCrossPlatformId.BranchCPID branchCPID, BranchErr
}
}
- protected class BranchLATDListener implements BranchLastAttributedTouchData.BranchLastAttributedTouchDataListener {
+ protected class BranchLATDListener implements BranchLastAttributedTouchDataListener {
private CallbackContext _callbackContext;
public BranchLATDListener(CallbackContext callbackContext) {
diff --git a/src/ios/AppDelegate+BranchSdk.m b/src/ios/AppDelegate+BranchSdk.m
index 91a968f5..d09670ca 100644
--- a/src/ios/AppDelegate+BranchSdk.m
+++ b/src/ios/AppDelegate+BranchSdk.m
@@ -8,6 +8,9 @@
#import
#endif
+// Provides Ionic Capacitor compatibility
+#import
+
@interface AppDelegate (BranchSDK)
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler;
diff --git a/src/ios/BranchSDK.m b/src/ios/BranchSDK.m
index d0f9a307..199a7191 100644
--- a/src/ios/BranchSDK.m
+++ b/src/ios/BranchSDK.m
@@ -1,5 +1,7 @@
#import "BranchSDK.h"
+NSString * const pluginVersion = @"4.1.0";
+
@interface BranchSDK()
@property (strong, nonatomic) NSString *deepLinkUrl;
@@ -77,6 +79,7 @@ - (void)continueUserActivity:(CDVInvokedUrlCommand*)command
- (void)initSession:(CDVInvokedUrlCommand*)command
{
+ [[Branch getInstance] registerPluginName:"CordovaIonic" versio:pluginVersion];
[[Branch getInstance] initSessionWithLaunchOptions:nil andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
NSString *resultString = nil;
@@ -746,7 +749,7 @@ - (void)listOnSpotlight:(CDVInvokedUrlCommand*)command {
- (void)crossPlatformIds:(CDVInvokedUrlCommand *)command {
NSMutableDictionary *json = [NSMutableDictionary new];
-
+
Branch *branch = [self getInstance];
[branch crossPlatformIdDataWithCompletion:^(BranchCrossPlatformID *cpid) {
CDVPluginResult* pluginResult = nil;
@@ -760,9 +763,9 @@ - (void)crossPlatformIds:(CDVInvokedUrlCommand *)command {
for (BranchProbabilisticCrossPlatformID *tmp in cpid.probabiliticCrossPlatformIDs) {
if (tmp.crossPlatformID && tmp.score) {
NSMutableDictionary *pair = [NSMutableDictionary new];
- [pair setObject:tmp.crossPlatformID forKey:@"id"];
+ [pair setObject:tmp.crossPlatformID forKey:@"id"];
[pair setObject:tmp.score forKey:@"probability"];
- [probCPIDs addObject:pair];
+ [probCPIDs addObject:pair];
}
}
[json setObject:probCPIDs forKey:@"prob_cross_platform_ids"];
@@ -777,9 +780,9 @@ - (void)crossPlatformIds:(CDVInvokedUrlCommand *)command {
- (void)lastAttributedTouchData:(CDVInvokedUrlCommand *)command {
NSMutableDictionary *json = [NSMutableDictionary new];
-
+
Branch *branch = [self getInstance];
- [branch lastTouchAttributedDataWithCompletion:^(BranchLastAttributedTouchData * _Nullable latd) {
+ [branch lastAttributedTouchDataWithAttributionWindow:30 completion:^(BranchLastAttributedTouchData * _Nullable latd) {
CDVPluginResult* pluginResult = nil;
if (latd) {
[json setObject:latd.attributionWindow forKey:@"attribution_window"];
diff --git a/src/scripts/hooks/beforePrepare.js b/src/scripts/hooks/beforePrepare.js
index 91027b13..a5c8053c 100644
--- a/src/scripts/hooks/beforePrepare.js
+++ b/src/scripts/hooks/beforePrepare.js
@@ -1,9 +1,8 @@
-(function() {
+(function () {
// properties
const configPreferences = require("../npm/processConfigXml.js");
const iosPlist = require("../ios/updatePlist.js");
- const iosCapabilities = require("../ios/enableEntitlements.js");
const iosAssociatedDomains = require("../ios/updateAssociatedDomains.js");
const IOS = "ios";
@@ -18,7 +17,6 @@
platforms.forEach(platform => {
if (platform === IOS) {
iosPlist.addBranchSettings(preferences);
- iosCapabilities.enableAssociatedDomains(preferences);
iosAssociatedDomains.addAssociatedDomains(preferences);
}
});
diff --git a/src/scripts/ios/enableEntitlements.js b/src/scripts/ios/enableEntitlements.js
deleted file mode 100644
index 4cfb93f8..00000000
--- a/src/scripts/ios/enableEntitlements.js
+++ /dev/null
@@ -1,110 +0,0 @@
-(function() {
- // properties
-
- const path = require("path");
- const compare = require("node-version-compare");
- const IOS_DEPLOYMENT_TARGET = "8.0";
- const COMMENT_KEY = /_comment$/;
- const DEBUGCODESIGNIDENTITY = "iPhone Developer";
- const RELEASECODESIGNIDENTITY = "iPhone Distribution";
-
- // entry
- module.exports = {
- enableAssociatedDomains: enableAssociatedDomains
- };
-
- // updates the xcode preferences to allow associated domains
- function enableAssociatedDomains(preferences) {
- const entitlementsFile = path.join(
- preferences.projectRoot,
- "platforms",
- "ios",
- preferences.projectName,
- "Resources",
- `${preferences.projectName}.entitlements`
- );
-
- activateAssociativeDomains(
- preferences.iosProjectModule.xcode,
- entitlementsFile
- );
- addPbxReference(preferences.iosProjectModule.xcode, entitlementsFile);
- preferences.iosProjectModule.write();
- }
-
- // adds entitlement files to the xcode project
- function activateAssociativeDomains(xcodeProject, entitlementsFile) {
- const configurations = removeComments(
- xcodeProject.pbxXCBuildConfigurationSection()
- );
- let config;
- let configurationConfig;
- let buildSettings;
-
- for (config in configurations) {
- configurationConfig = configurations[config];
- buildSettings = configurationConfig.buildSettings;
-
- buildSettings.CODE_SIGN_ENTITLEMENTS = `"${entitlementsFile}"`;
-
- if (configurationConfig.name === 'Release') {
- buildSettings.CODE_SIGN_IDENTITY = `"${RELEASECODESIGNIDENTITY}"`;
- } else {
- buildSettings.CODE_SIGN_IDENTITY = `"${DEBUGCODESIGNIDENTITY}"`;
- }
-
- // if deployment target is less then the required one - increase it
- if (buildSettings.IPHONEOS_DEPLOYMENT_TARGET) {
- const buildDeploymentTarget = buildSettings.IPHONEOS_DEPLOYMENT_TARGET.toString();
- if (compare(buildDeploymentTarget, IOS_DEPLOYMENT_TARGET) === -1) {
- buildSettings.IPHONEOS_DEPLOYMENT_TARGET = IOS_DEPLOYMENT_TARGET;
- }
- } else {
- buildSettings.IPHONEOS_DEPLOYMENT_TARGET = IOS_DEPLOYMENT_TARGET;
- }
- }
- }
-
- function addPbxReference(xcodeProject, entitlementsFile) {
- const fileReferenceSection = removeComments(
- xcodeProject.pbxFileReferenceSection()
- );
-
- if (isPbxReferenceAlreadySet(fileReferenceSection, entitlementsFile))
- return;
- xcodeProject.addResourceFile(path.basename(entitlementsFile));
- }
-
- function isPbxReferenceAlreadySet(fileReferenceSection, entitlementsFile) {
- let isAlreadyInReferencesSection = false;
- let uuid;
- let fileRefEntry;
-
- for (uuid in fileReferenceSection) {
- fileRefEntry = fileReferenceSection[uuid];
- if (
- fileRefEntry.path &&
- fileRefEntry.path.indexOf(entitlementsFile) > -1
- ) {
- isAlreadyInReferencesSection = true;
- break;
- }
- }
-
- return isAlreadyInReferencesSection;
- }
-
- // removes comments from .pbx file
- function removeComments(obj) {
- const keys = Object.keys(obj);
- const newObj = {};
-
- for (let i = 0, len = keys.length; i < len; i++) {
- if (!COMMENT_KEY.test(keys[i])) {
- newObj[keys[i]] = obj[keys[i]];
- }
- }
-
- return newObj;
- }
-})();
diff --git a/src/scripts/ios/updateAssociatedDomains.js b/src/scripts/ios/updateAssociatedDomains.js
index f921a819..eddb7563 100644
--- a/src/scripts/ios/updateAssociatedDomains.js
+++ b/src/scripts/ios/updateAssociatedDomains.js
@@ -1,10 +1,12 @@
-(function() {
+(function () {
// properties
const path = require("path");
const fs = require("fs");
const plist = require("plist");
const mkpath = require("mkpath");
+ // TODO [codinronan 15.01.2020]: Read these from {preferences.projectName}.plist --
+ // most people don't change them, but some do, and more importantly, some people add new ones!
const BUILD_TYPES = ["Debug", "Release"];
const ASSOCIATED_DOMAINS = "com.apple.developer.associated-domains";
@@ -29,24 +31,6 @@
// get the xcode .entitlements and provisioning profile .plist
function getEntitlementFiles(preferences) {
const files = [];
- const entitlements = path.join(
- preferences.projectRoot,
- "platforms",
- "ios",
- preferences.projectName,
- "Resources",
- `${preferences.projectName}.entitlements`
- );
- files.push(
- path.join(
- preferences.projectRoot,
- "platforms",
- "ios",
- preferences.projectName,
- `${preferences.projectName}.entitlements`
- )
- );
- files.push(entitlements);
for (let i = 0; i < BUILD_TYPES.length; i++) {
const buildType = BUILD_TYPES[i];