Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit c0d121e

Browse files
Automate enabling iOS 10 keychain sharing #216
1 parent 355d43f commit c0d121e

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var xcode = require('xcode'),
2+
fs = require('fs'),
3+
path = require('path'),
4+
appRoot = require('app-root-path').toString(),
5+
pjson = require(path.join(appRoot, 'package.json')),
6+
util = require('util'),
7+
iosFolder = path.join(appRoot, 'platforms', 'ios');
8+
9+
fs.readdir(iosFolder, function (err, data) {
10+
if (err) {
11+
throw err;
12+
}
13+
14+
var projFolder;
15+
var projName;
16+
17+
// Find the project folder by looking for *.xcodeproj
18+
if (data && data.length) {
19+
data.forEach(function (folder) {
20+
if (folder.match(/\.xcodeproj$/)) {
21+
projFolder = path.join(iosFolder, folder);
22+
projName = path.basename(folder, '.xcodeproj');
23+
}
24+
});
25+
}
26+
27+
if (!projFolder || !projName) {
28+
throw new Error("Could not find an .xcodeproj folder in: " + iosFolder);
29+
}
30+
31+
var destFolder = path.join(iosFolder, projName, 'Resources');
32+
if (!fs.existsSync(destFolder)) {
33+
fs.mkdirSync(destFolder);
34+
}
35+
36+
var destFile = path.join(destFolder, projName + '.entitlements');
37+
38+
if (!fs.existsSync(destFile)) {
39+
var bundleID = pjson.nativescript.id;
40+
41+
// create a new entitlements plist file
42+
var sourceFile = path.join(appRoot, 'node_modules', 'nativescript-plugin-firebase', 'scripts', 'resources', 'KeychainSharing.entitlements');
43+
44+
fs.readFile(sourceFile, 'utf8', function (err, data) {
45+
data = data.replace(/__KEYCHAIN_ACCESS_GROUP__/g, bundleID);
46+
47+
fs.writeFileSync(destFile, data);
48+
49+
var projectPath = path.join(projFolder, 'project.pbxproj'),
50+
pbxProject = xcode.project(projectPath);
51+
52+
pbxProject.parseSync();
53+
pbxProject.addResourceFile(path.join("Firebase", "Resources", projName + ".entitlements"));
54+
55+
var configGroups = pbxProject.hash.project.objects['XCBuildConfiguration'];
56+
for (var key in configGroups) {
57+
var config = configGroups[key];
58+
if (config.buildSettings !== undefined) {
59+
config.buildSettings.CODE_SIGN_ENTITLEMENTS = '"' + projName + '/Resources/' + projName + '.entitlements"';
60+
}
61+
}
62+
63+
// write the updated project file
64+
fs.writeFileSync(projectPath, pbxProject.writeSync());
65+
});
66+
}
67+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>keychain-access-groups</key>
6+
<array>
7+
<string>$(AppIdentifierPrefix)__KEYCHAIN_ACCESS_GROUP__</string>
8+
</array>
9+
</dict>
10+
</plist>

0 commit comments

Comments
 (0)