diff --git a/README.md b/README.md
index 62feabe5..604efec0 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,23 @@ To install the plugin in your Cordova app, run the following:
```script
cordova plugin add cordova-plugin-intercom
```
+
+The Intercom iOS SDK is no longer published to the CocoaPods trunk. When the plugin is added to the iOS platform, it downloads
+`Intercom.xcframework.zip` for the exact iOS SDK version this release was built against from the
+[intercom-ios GitHub release](https://github.com/intercom/intercom-ios/releases), verifies its SHA-256 checksum and embeds it
+in your app. The download is cached in `~/Library/Caches/cordova-plugin-intercom`; set `INTERCOM_IOS_SDK_CACHE_DIR` to use
+another directory, for example one your CI caches or one you pre-fill for offline builds. The download comes from `github.com`,
+which redirects to `release-assets.githubusercontent.com`, so allow both hosts if your network only allows the CocoaPods CDN.
+
+If you are upgrading from a version that installed the `Intercom` pod, remove and re-add the plugin
+(`cordova plugin rm cordova-plugin-intercom`, then `cordova plugin add cordova-plugin-intercom`) so the pod is removed from
+`platforms/ios/Podfile`, and remove `pod 'Intercom'` if you added it yourself. If the app still links the old pod afterwards,
+remove and re-add the platform (`cordova platform rm ios`, then `cordova platform add ios`).
+
+The pod-based plugin also added `use_frameworks!` to the generated Podfile. Pods from your other plugins are now built as
+static libraries unless another plugin asks for frameworks, so duplicate symbol errors or missing resource bundles from those
+pods after upgrading come from this change.
+
### PhoneGap
To add the plugin to your PhoneGap app, add the following to your `config.xml`:
diff --git a/intercom-plugin/.gitignore b/intercom-plugin/.gitignore
new file mode 100644
index 00000000..e09cefe1
--- /dev/null
+++ b/intercom-plugin/.gitignore
@@ -0,0 +1,2 @@
+src/ios/Intercom.xcframework/
+src/ios/.intercom-ios-sdk
diff --git a/intercom-plugin/package-lock.json b/intercom-plugin/package-lock.json
index 0660b9fb..bfb3eebc 100644
--- a/intercom-plugin/package-lock.json
+++ b/intercom-plugin/package-lock.json
@@ -8,9 +8,6 @@
"name": "cordova-plugin-intercom",
"version": "16.7.0",
"license": "MIT License",
- "dependencies": {
- "q": "^1.5.1"
- },
"engines": {
"cordovaDependencies": {
"14.1.1": {
@@ -30,23 +27,6 @@
}
}
}
- },
- "node_modules/q": {
- "version": "1.5.1",
- "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
- "integrity": "sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==",
- "license": "MIT",
- "engines": {
- "node": ">=0.6.0",
- "teleport": ">=0.2.0"
- }
- }
- },
- "dependencies": {
- "q": {
- "version": "1.5.1",
- "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
- "integrity": "sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw=="
}
}
}
diff --git a/intercom-plugin/package.json b/intercom-plugin/package.json
index 9074f4c0..714547ad 100644
--- a/intercom-plugin/package.json
+++ b/intercom-plugin/package.json
@@ -23,9 +23,6 @@
"cordova-ios",
"cordova-android"
],
- "dependencies": {
- "q": "^1.5.1"
- },
"engines": {
"cordovaDependencies": {
"14.1.1": {
diff --git a/intercom-plugin/plugin.xml b/intercom-plugin/plugin.xml
index 41c604e5..dae0e95c 100644
--- a/intercom-plugin/plugin.xml
+++ b/intercom-plugin/plugin.xml
@@ -27,8 +27,7 @@
-
-
+
@@ -63,14 +62,8 @@
-
-
-
-
-
-
-
-
+
+
diff --git a/intercom-plugin/scripts/checkForUpdate.js b/intercom-plugin/scripts/checkForUpdate.js
deleted file mode 100644
index b53f4d5d..00000000
--- a/intercom-plugin/scripts/checkForUpdate.js
+++ /dev/null
@@ -1,105 +0,0 @@
-var fs = require('fs');
-
-function fetchUpdateInfo(callback) {
- var updateInfo = {
- releaseDate: 0,
- podUpdateDate: 0,
- lastCheckDate: 0
- };
-
- fs.readFile('platforms/ios/.intercom_update', 'utf8', function (err, data) {
- if (!err) {
- obj = JSON.parse(data);
- updateInfo.podUpdateDate = obj.podUpdateDate;
- updateInfo.releaseDate = obj.releaseDate;
- updateInfo.lastCheckDate = obj.lastCheckDate;
- }
- callback(updateInfo);
- });
-}
-
-function writeUpdateInfo(updateInfo, callback) {
- fs.writeFile('platforms/ios/.intercom_update', JSON.stringify(updateInfo), 'utf8', function (err,data) {
- callback();
- });
-}
-
-function updateIntercomIfNeeded(updateInfo, callback) {
- var exec = require('child_process').exec;
- var completion = function() {
- writeUpdateInfo(updateInfo, function() {
- callback();
- });
- };
-
- if (updateInfo.releaseDate > updateInfo.podUpdateDate) {
- console.log("Updating Intercom");
- exec('cd platforms/ios && pod update Intercom', function(error, stdout, stderr) {
- if (!error) {
- console.log(stdout);
- updateInfo.podUpdateDate = Date.now();
- }
- completion();
- });
- } else {
- completion();
- }
-}
-
-function fetchLatestRelease(callback) {
- var https = require('https');
-
- var req = https.get({
- headers: {
- accept: 'application/json',
- 'User-Agent': 'Intercom-Cordova-Plugin'
- },
- host: 'api.github.com',
- path: '/repos/intercom/intercom-ios/releases/latest'
- }, function(response) {
- if (response.statusCode != 200) {
- callback(null);
- return;
- }
-
- var body = '';
- response.on('data', function(d) {
- body += d;
- });
- response.on('end', function() {
- var parsedResponse = JSON.parse(body);
- callback(parsedResponse);
- });
- });
- req.on('error', function(e) {
- callback(null);
- });
-}
-
-module.exports = function() {
- var q = require('q');
- var deferral = new q.defer();
-
- fetchUpdateInfo(function(updateInfo) {
- // Check at most once every 48 hours
- if (Date.now() - updateInfo.lastCheckDate > 1000 * 60 * 60 * 48) {
- fetchLatestRelease(function(releaseData) {
- updateInfo.lastCheckDate = Date.now();
-
- if (releaseData != null) {
- updateInfo.releaseDate = Date.parse(releaseData['published_at']);
- } else {
- // last release date is unavailable, set it to today so that the pod is installed
- updateInfo.releaseDate = Date.now();
- }
-
- updateIntercomIfNeeded(updateInfo, function() {
- deferral.resolve();
- });
- });
- } else {
- deferral.resolve();
- }
- });
- return deferral.promise;
-}
diff --git a/intercom-plugin/scripts/installIntercomIosSdk.js b/intercom-plugin/scripts/installIntercomIosSdk.js
new file mode 100644
index 00000000..a26873a6
--- /dev/null
+++ b/intercom-plugin/scripts/installIntercomIosSdk.js
@@ -0,0 +1,65 @@
+var crypto = require('crypto');
+var execFileSync = require('child_process').execFileSync;
+var fs = require('fs');
+var os = require('os');
+var path = require('path');
+
+// The Intercom pod is no longer published to the CocoaPods trunk; fetch the GitHub release instead.
+var VERSION = '19.9.2';
+var SHA256 = '6af284508f58de833313b263f3d82eaebc255c4d9a56ad9adf2fc6af4228c0f4';
+var RELEASE_URL = 'https://github.com/intercom/intercom-ios/releases/download/' + VERSION + '/Intercom.xcframework.zip';
+
+function cacheDir() {
+ return process.env.INTERCOM_IOS_SDK_CACHE_DIR || path.join(os.homedir(), 'Library', 'Caches', 'cordova-plugin-intercom');
+}
+
+function sha256(file) {
+ return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
+}
+
+function cachedZip() {
+ var zipPath = path.join(cacheDir(), VERSION, 'Intercom.xcframework.zip');
+ if (fs.existsSync(zipPath) && sha256(zipPath) === SHA256) {
+ return zipPath;
+ }
+
+ var downloadPath = zipPath + '.download';
+ fs.mkdirSync(path.dirname(zipPath), { recursive: true });
+ console.log('[Intercom] Downloading the Intercom iOS SDK ' + VERSION + ' from ' + RELEASE_URL);
+ try {
+ execFileSync('curl', ['--fail', '--silent', '--show-error', '--location', '--retry', '3', '--output', downloadPath, RELEASE_URL], { stdio: 'inherit' });
+ } catch (error) {
+ fs.rmSync(downloadPath, { force: true });
+ throw new Error('[Intercom] Could not download ' + RELEASE_URL + '. Check your network, or place the zip at ' + zipPath +
+ ' (set INTERCOM_IOS_SDK_CACHE_DIR to use another cache directory).');
+ }
+
+ var actual = sha256(downloadPath);
+ if (actual !== SHA256) {
+ fs.rmSync(downloadPath, { force: true });
+ throw new Error('[Intercom] Checksum mismatch for ' + RELEASE_URL + ': expected ' + SHA256 + ', got ' + actual + '.');
+ }
+ fs.renameSync(downloadPath, zipPath);
+ return zipPath;
+}
+
+module.exports = function (context) {
+ var frameworkPath = path.join(context.opts.plugin.dir, 'src', 'ios', 'Intercom.xcframework');
+ var stampPath = path.join(path.dirname(frameworkPath), '.intercom-ios-sdk');
+ var stamp = VERSION + ' ' + SHA256;
+ if (fs.existsSync(path.join(frameworkPath, 'Info.plist')) && fs.existsSync(stampPath) &&
+ fs.readFileSync(stampPath, 'utf8') === stamp) {
+ return;
+ }
+
+ var zipPath = cachedZip();
+ var tmp = fs.mkdtempSync(path.join(path.dirname(frameworkPath), 'extract-'));
+ try {
+ execFileSync('unzip', ['-q', zipPath, '-d', tmp], { stdio: 'inherit' });
+ fs.rmSync(frameworkPath, { recursive: true, force: true });
+ fs.renameSync(path.join(tmp, 'Intercom.xcframework'), frameworkPath);
+ } finally {
+ fs.rmSync(tmp, { recursive: true, force: true });
+ }
+ fs.writeFileSync(stampPath, stamp);
+};
diff --git a/intercom-plugin/scripts/prepareCocoaPods.js b/intercom-plugin/scripts/prepareCocoaPods.js
deleted file mode 100644
index c035272a..00000000
--- a/intercom-plugin/scripts/prepareCocoaPods.js
+++ /dev/null
@@ -1,13 +0,0 @@
-module.exports = function() {
- var q = require('q');
- var exec = require('child_process').exec;
-
- var deferral = new q.defer();
-
- console.log('Fetching latest CocoaPods specs repo ');
- exec('pod repo update --verbose', function(error, stdout, stderr) {
- deferral.resolve();
- });
-
- return deferral.promise;
-}