Skip to content

Commit c03e55c

Browse files
authored
Merge pull request #660 from adrianyg7/issue642
Add branch header search paths to cocoapods config
2 parents e865a5c + 239e6c5 commit c03e55c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/scripts/hooks/beforePrepare.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const configPreferences = require("../npm/processConfigXml.js");
55
const iosPlist = require("../ios/updatePlist.js");
66
const iosAssociatedDomains = require("../ios/updateAssociatedDomains.js");
7+
const iosHeaderPaths = require("../ios/updateHeaderPaths.js");
78
const IOS = "ios";
89

910
// entry
@@ -18,6 +19,7 @@
1819
if (platform === IOS) {
1920
iosPlist.addBranchSettings(preferences);
2021
iosAssociatedDomains.addAssociatedDomains(preferences);
22+
iosHeaderPaths.addHeaderPaths();
2123
}
2224
});
2325
}

src/scripts/ios/updateHeaderPaths.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(function() {
2+
// properties
3+
4+
const fs = require("fs");
5+
6+
// entry
7+
module.exports = {
8+
addHeaderPaths: addHeaderPaths
9+
};
10+
11+
// updates the platforms/ios/cordova/build.xcconfig file with Branch's Header Paths
12+
// some plugins still use the old CocoaPods way to resolve config dirs or other obscure
13+
// ways that modify CocoaPods config. That causes the Branch plugin to fail on iOS build.
14+
function addHeaderPaths() {
15+
const filePath = "platforms/ios/cordova/build.xcconfig";
16+
let config = readBuildXcconfig(filePath);
17+
18+
config = updateHeaderPaths(config);
19+
writeBuildXcconfig(filePath, config);
20+
}
21+
22+
// update build.xcconfig with Branch's Header Paths
23+
function updateHeaderPaths(config) {
24+
config = config.split("\n")
25+
.map(function (line) {
26+
if (line.indexOf("HEADER_SEARCH_PATHS") > -1 && line.indexOf("Branch-SDK") === -1) {
27+
line += ' "${PODS_ROOT}/Branch/Branch-SDK/Branch-SDK" "${PODS_ROOT}/Branch/Branch-SDK/Branch-SDK/Networking" "${PODS_ROOT}/Branch/Branch-SDK/Branch-SDK/Networking/Requests"';
28+
}
29+
return line;
30+
});
31+
32+
return config.join("\n");
33+
}
34+
35+
function readBuildXcconfig(filePath) {
36+
return fs.readFileSync(filePath, "utf8");
37+
}
38+
39+
function writeBuildXcconfig(filePath, config) {
40+
return fs.writeFileSync(filePath, config, { encoding: "utf8" });
41+
}
42+
})();

0 commit comments

Comments
 (0)