Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting Custom Entitlements files #2075

Closed
SpoonIsBad opened this issue Sep 21, 2016 · 5 comments
Closed

Supporting Custom Entitlements files #2075

SpoonIsBad opened this issue Sep 21, 2016 · 5 comments
Labels

Comments

@SpoonIsBad
Copy link

SpoonIsBad commented Sep 21, 2016

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 SpoonIsBad changed the title Supporting Custom Entitlements.plist files Supporting Custom Entitlements files Sep 21, 2016
@enchev enchev added the feature label Oct 3, 2016
@ghost
Copy link

ghost commented Dec 25, 2016

@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.

@ghost
Copy link

ghost commented Dec 25, 2016

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.

@spike1292
Copy link

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

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

@joaoduartemariucio
Copy link

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

@Fatme
Copy link
Contributor

Fatme commented Jun 22, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants