我在这个问题上花了很多很多很多时间。
而且我想出了一个科尔多瓦after_prepare钩子,可以解决我在 XCode 7 和 8 上的问题。这里是......
"use strict";
var fs = require('fs');
var path = require('path');
var xcode = require('xcode');
module.exports = function (context)
{
var encoding = 'utf-8';
var plist = fs.readFileSync(path.resolve(__dirname, "../GoogleService-Info.plist"), encoding);
fs.writeFileSync(path.resolve(__dirname, "../platforms/ios/GoogleService-Info.plist"), plist, encoding);
var projectPath = path.resolve(__dirname, "../platforms/ios/APP NAME.xcodeproj/project.pbxproj");
var pbxFile = fs.readFileSync(projectPath, encoding);
var proj = new xcode.project(projectPath);
proj = proj.parseSync();
var pbxGroupKey = proj.findPBXGroupKey({
name: "Resources"
});
proj.removeResourceFile('GoogleService-Info.plist', {}, pbxGroupKey);
proj.addResourceFile('GoogleService-Info.plist', {}, pbxGroupKey);
proj.addBuildProperty('"CODE_SIGN_IDENTITY[sdk=iphoneos*]"', '"iPhone Distribution"', 'Release');
proj.addBuildProperty('DEVELOPMENT_TEAM', 'XXXXXXXX', 'Release');
proj.addBuildProperty('PROVISIONING_PROFILE', "XXXXXXXX-XXXXXXXX-XXXX-XXXX-XXXXXXXX", 'Release');
proj.addBuildProperty('PROVISIONING_PROFILE_SPECIFIER', '"NAME OF PROFILE"', 'Release');
proj.addBuildProperty('TARGETED_DEVICE_FAMILY', '"1,2"', 'Release');
proj.addTargetAttribute("DevelopmentTeam", "XXXXXXXX");
var pushEntitlement = "{com.apple.Push ={enabled = 1;};}";
proj.addTargetAttribute("SystemCapabilities", pushEntitlement);
/*var attributes = proj.getFirstProject()['firstProject']['attributes'];
if (attributes['TargetAttributes'] === undefined)
{
attributes['TargetAttributes'] = {};
}
var target = proj.getFirstTarget();
if (attributes['TargetAttributes'][target.uuid] === undefined)
{
attributes['TargetAttributes'][target.uuid] = {};
}
attributes['TargetAttributes'][target.uuid]["SystemCapabilities"] = "{com.apple.Push ={enabled = 1;};}";
*/
fs.writeFileSync(projectPath, proj.writeSync());
fs.writeFileSync(path.resolve(__dirname, "../platforms/ios/APP NAME/Resources/GoogleService-Info.plist"), plist, encoding);
fs.writeFileSync(path.resolve(__dirname, "../platforms/ios/APP NAME/Resources/Resources/GoogleService-Info.plist"), plist, encoding);
};
只需记住更新您的 APP 名称、配置文件名称和团队 ID。