Skip to content

Commit

Permalink
EddyVerbruggen#280 Not Working on IOS 10
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Sep 28, 2016
1 parent 8db84ae commit 1e8f388
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.DS_Store
*.iml
npm-debug.log
94 changes: 94 additions & 0 deletions hooks/ios/install_entitlements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// using error to see if this shows up in AB
console.error("Running hook to add iOS Keychain Sharing entitlements (required since iOS 10)");

var xcode = require('xcode'),
fs = require('fs'),
path = require('path'),
plist = require('plist'),
util = require('util');

module.exports = function (context) {
var Q = context.requireCordovaModule('q');
var deferral = new Q.defer();

if (context.opts.cordova.platforms.indexOf('ios') < 0) {
throw new Error('This plugin expects the ios platform to exist.');
}

var iosPlatform = path.join(context.opts.projectRoot, 'platforms/ios/');
var iosFolder = fs.existsSync(iosPlatform) ? iosPlatform : context.opts.projectRoot;
console.log("iosFolder: " + iosFolder);

fs.readdir(iosFolder, function (err, data) {
if (err) {
throw err;
}

var projFolder;
var projName;

// Find the project folder by looking for *.xcodeproj
if (data && data.length) {
data.forEach(function (folder) {
if (folder.match(/\.xcodeproj$/)) {
projFolder = path.join(iosFolder, folder);
projName = path.basename(folder, '.xcodeproj');
}
});
}

if (!projFolder || !projName) {
throw new Error("Could not find an .xcodeproj folder in: " + iosFolder);
}

var destFile = path.join(iosFolder, projName, 'Resources', projName + '.entitlements');
if (fs.existsSync(destFile)) {
console.error("File exists, not doing anything: " + destFile);
} else {
console.log("Will add iOS Keychain Sharing entitlements to project '" + projName + "'");

//var projectPlistPath = path.join(context.opts.projectRoot, 'platforms/ios', projName, util.format('%s-Info.plist', projName));
var projectPlistPath = path.join(iosFolder, projName, util.format('%s-Info.plist', projName));
var projectPlistJson = plist.parse(fs.readFileSync(projectPlistPath, 'utf8'));
var bundleID = projectPlistJson.CFBundleIdentifier;
console.log("KeychainSharingBundleID: " + bundleID);


// create a new entitlements plist file
var sourceFile = path.join(context.opts.plugin.pluginInfo.dir, 'src/ios/resources/KeychainSharing.entitlements');
fs.readFile(sourceFile, 'utf8', function (err, data) {
data = data.replace(/__KEYCHAIN_ACCESS_GROUP__/g, bundleID);

fs.writeFileSync(destFile, data);

var projectPath = path.join(projFolder, 'project.pbxproj');

var pbxProject;
if (context.opts.cordova.project) {
pbxProject = context.opts.cordova.project.parseProjectFile(context.opts.projectRoot).xcode;
} else {
pbxProject = xcode.project(projectPath);
pbxProject.parseSync();
}

pbxProject.addResourceFile(projName + ".entitlements");

var configGroups = pbxProject.hash.project.objects['XCBuildConfiguration'];
for (var key in configGroups) {
var config = configGroups[key];
if (config.buildSettings !== undefined) {
config.buildSettings.CODE_SIGN_ENTITLEMENTS = '"' + projName + '/Resources/' + projName + '.entitlements"';
}
}

// write the updated project file
fs.writeFileSync(projectPath, pbxProject.writeSync());
console.warn("OK, added iOS Keychain Sharing entitlements to project '" + projName + "'");

deferral.resolve();
});
}
});

return deferral.promise;
};
6 changes: 6 additions & 0 deletions hooks/ios/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"xcode": "0.8.0",
"plist": "1.1.0"
}
}
17 changes: 17 additions & 0 deletions hooks/ios/prerequisites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
console.error("Google Sign-In prerequisites");

module.exports = function (context) {
var child_process = context.requireCordovaModule('child_process'),
deferral = context.requireCordovaModule('q').defer();

var output = child_process.exec('npm install', {cwd: __dirname},
function (error) {
if (error !== null) {
console.log('exec error: ' + error);
deferral.reject('npm installation failed');
}
deferral.resolve();
});

return deferral.promise;
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "5.0.3",
"version": "5.1.0",
"name": "cordova-plugin-googleplus",
"cordova_name": "Google SignIn",
"description": "Use your Google account to authenticate with the app.",
Expand All @@ -9,6 +9,7 @@
"keywords": [
"Google",
"Google SignIn",
"Google Sign In",
"GoogleSignIn",
"Google Login",
"Google Plus",
Expand All @@ -27,7 +28,7 @@
"engines": [
{
"name": "cordova",
"version": ">=3.3.0"
"version": ">=3.5.0"
}
]
}
8 changes: 6 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-googleplus"
version="5.0.3">
version="5.1.0">

<name>Google SignIn</name>

Expand All @@ -19,7 +19,7 @@
<issue>https://github.com/EddyVerbruggen/cordova-plugin-googleplus/issues</issue>

<engines>
<engine name="cordova" version=">=3.3.0"/>
<engine name="cordova" version=">=3.5.0"/>
</engines>

<js-module src="www/GooglePlus.js" name="GooglePlus">
Expand Down Expand Up @@ -92,9 +92,13 @@
<framework src="AddressBook.framework" weak="true" />
<framework src="CoreText.framework" weak="true" />
<framework src="SafariServices.framework" weak="true" />
<framework src="Security.framework" weak="true" />
<framework src="SystemConfiguration.framework" weak="true" />
<framework src="libz.tbd" weak="true" />
<framework src="libz.dylib" weak="true" />

<hook type="after_plugin_install" src="hooks/ios/prerequisites.js"/>
<hook type="after_plugin_install" src="hooks/ios/install_entitlements.js" />
</platform>

</plugin>
10 changes: 10 additions & 0 deletions src/ios/resources/KeychainSharing.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)__KEYCHAIN_ACCESS_GROUP__</string>
</array>
</dict>
</plist>

0 comments on commit 1e8f388

Please sign in to comment.