NativeScript/nativescript-cli

Supporting Custom Entitlements files

Closed this issue · 5 comments

Is it possible to have a custom Entitlements.plist file in App_Resources like it is possible to have a custom Info.plist file? #1089

I tried dropping a Entitlements.plist in my App_Resources file, but when I navigate to platforms/ios/MyApp/ I notice there is no prepended MyApp-Entitlements.plist, and instead it still lives inside of the platforms/ios/MyApp/Resources/ folder. As a result I'm guessing the answer to my question is no.

EDIT
Upon messing with this more, I realize the correct file I need is a .entitlements file, not an entitlements.plist, in my case it'd be MyApp.entitlements

@SpoonIsBad @enchev It also needs to add the CODE_SIGN_ENTITLEMENTS variable to the xcconfig

This feature is necessary for CI builds because Xcode 8 no longer copies the entitlements from the provisioning profile. So, if for example, you are doing a CI build, it will have zero entitlements.

This causes any plugins that use entitlements (i.e. push notifications) to break if built in a CI environment, where going into Xcode and toggling the entitlement in a GUI isn't possible.

A .entitlements file in app/App_Resources/iOS/ copied to platforms/ios/abc/abc.entitlements would be great. I have to do this with an after-prepare hook atm.

For anyone else who needs to build in CI right now, this is what I use:

before-prepare/xcode-8-entitlements.js:

var fs = require('fs-extra');
var path = require('path');

module.exports = function(logger, platformsData, projectData, hookArgs) {
	var platform = hookArgs.platform.toLowerCase(),
		appResourcesDirectoryPath = projectData.appResourcesDirectoryPath,
		platformResourcesDirectory = path.join(appResourcesDirectoryPath, "iOS");

	return new Promise(function(resolve, reject) {
		if (platform == 'ios') {
			var target = path.join(platformResourcesDirectory, "build.xcconfig");

			try {
				fs.writeFileSync(target, "CODE_SIGN_ENTITLEMENTS = " + path.join(projectData.projectName, projectData.projectName + ".entitlements"));
			} catch (error) {
				reject();
			}
		}

		resolve();
	});
};

after-prepare/xcode-8-entitlements.js:

var fs = require('fs-extra');
var path = require('path');

module.exports = function(logger, platformsData, projectData, hookArgs) {
	var platform = hookArgs.platform.toLowerCase(),
		appResourcesDirectoryPath = projectData.appResourcesDirectoryPath,
		entitlementsFile = path.join(appResourcesDirectoryPath, "iOS", ".entitlements"),
		projectRoot = path.join(projectData.platformsDir, "ios"),
		project = path.join(projectRoot, projectData.projectName);

	return new Promise(function(resolve, reject) {
		try {
			if (fs.existsSync(entitlementsFile)) {
				if (platform == 'ios') {
					fs.copySync(entitlementsFile, path.join(project, projectData.projectName + ".entitlements"), { clobber: true });
				}
			}
		} catch (error) {
			console.error(error);
			reject();
		}

		resolve();
	});
};

You'll need to have a .entitlements file in the App_Resources/iOS folder copied from running Xcode once.

@vbresults tnx for the suggestion, I created a plugin based on your code!

https://github.com/Essent/nativescript-custom-entitlements

The script not function in my project. Is there any new solution to the problem?

Fatme commented

Hi @joaoduartemariucio,

Can you please give us more info in order to help you to resolve the problem?

  1. Where is located your script?
  2. What is the name of your script?