From 1e8f3888549593b3e9eb096b2dc48182e72d79a1 Mon Sep 17 00:00:00 2001 From: "eddyverbruggen@gmail.com" Date: Wed, 28 Sep 2016 10:27:52 +0200 Subject: [PATCH] #280 Not Working on IOS 10 --- .gitignore | 1 + hooks/ios/install_entitlements.js | 94 +++++++++++++++++++ hooks/ios/package.json | 6 ++ hooks/ios/prerequisites.js | 17 ++++ package.json | 5 +- plugin.xml | 8 +- .../resources/KeychainSharing.entitlements | 10 ++ 7 files changed, 137 insertions(+), 4 deletions(-) create mode 100755 hooks/ios/install_entitlements.js create mode 100644 hooks/ios/package.json create mode 100644 hooks/ios/prerequisites.js create mode 100644 src/ios/resources/KeychainSharing.entitlements diff --git a/.gitignore b/.gitignore index 9f475082..027b0a9f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea +.DS_Store *.iml npm-debug.log \ No newline at end of file diff --git a/hooks/ios/install_entitlements.js b/hooks/ios/install_entitlements.js new file mode 100755 index 00000000..8fa54676 --- /dev/null +++ b/hooks/ios/install_entitlements.js @@ -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; +}; \ No newline at end of file diff --git a/hooks/ios/package.json b/hooks/ios/package.json new file mode 100644 index 00000000..bec68c17 --- /dev/null +++ b/hooks/ios/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "xcode": "0.8.0", + "plist": "1.1.0" + } +} \ No newline at end of file diff --git a/hooks/ios/prerequisites.js b/hooks/ios/prerequisites.js new file mode 100644 index 00000000..8750f8ec --- /dev/null +++ b/hooks/ios/prerequisites.js @@ -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; +}; \ No newline at end of file diff --git a/package.json b/package.json index 7af208e7..ff371837 100644 --- a/package.json +++ b/package.json @@ -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.", @@ -9,6 +9,7 @@ "keywords": [ "Google", "Google SignIn", + "Google Sign In", "GoogleSignIn", "Google Login", "Google Plus", @@ -27,7 +28,7 @@ "engines": [ { "name": "cordova", - "version": ">=3.3.0" + "version": ">=3.5.0" } ] } diff --git a/plugin.xml b/plugin.xml index 269856e8..42c2a4a4 100755 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="5.1.0"> Google SignIn @@ -19,7 +19,7 @@ https://github.com/EddyVerbruggen/cordova-plugin-googleplus/issues - + @@ -92,9 +92,13 @@ + + + + diff --git a/src/ios/resources/KeychainSharing.entitlements b/src/ios/resources/KeychainSharing.entitlements new file mode 100644 index 00000000..8b291caf --- /dev/null +++ b/src/ios/resources/KeychainSharing.entitlements @@ -0,0 +1,10 @@ + + + + + keychain-access-groups + + $(AppIdentifierPrefix)__KEYCHAIN_ACCESS_GROUP__ + + + \ No newline at end of file