Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 8: different entitlements for each scheme causing errors

I found an issue with Xcode 8 where .entitlements files are not being referenced properly for each scheme. Basically, my Debug .entitlements file is being referenced for my Release scheme. This is causing an issue because we implemented the new Rich push notification logic and that requires the use of App groups.

I am using two different teams (Development and Production), so there will be two specific App Groups.

like image 675
Tim Walsh Avatar asked Sep 13 '16 09:09

Tim Walsh


People also ask

How do I manage Xcode schemes?

The configurations that we just created now need to be associated with an XCode scheme. For more information on what a scheme is, check out the apple documentation reference here. To do so, we need to manage the schemes of the project. Open the scheme manager. Select Product -> Scheme -> Manage Schemes … from the toolbar. 2.

Why is my code not working on Xcode?

If you run your app and you get some build errors, that means Xcode has detected that the syntax of your code is wrong. If Xcode is complaining that a specific identifier doesn’t exist, then check that all of your opening curly braces have corresponding closing curly braces.

How to find the error message when your Xcode app crashes?

After the crash, go to Xcode in the lower right hand pane, scroll all the way to the top. So now that you know how to find the actual error message when your app crashes, the next step is to learn to recognize some of the more common types of messages because they will hint at what’s wrong.

Why does my Xcode Interface look different?

My Xcode Interface Is Different 1. Xcode Simulator Errors My iPhone simulator looks different? If your iPhone simulator doesn’t look like the one you see me using in my videos, it’s because your iOS simulator is at a different zoom level.


2 Answers

I found a solution. Make one .entitlements file add this:

<key>aps-environment</key>
<string>$(APS_ENVIRONMENT)</string>
<key>com.apple.security.application-groups</key>
<array>
    <string>$(APP_GROUP)</string>
</array>

Then in Target > Build settings Set the same .entitlements file in Signing > Code Signing Entitlements Add User-Defined Setting for APS_ENVIRONMENT and APP_GROUP setting the correct group for each target.

So, based on the target Xcode will use what you set for APS_ENVIRONMENT and APP_GROUP.

You can do this in plist too...did some amazing clean up today.

like image 82
Tim Walsh Avatar answered Oct 21 '22 04:10

Tim Walsh


Though Tim's solution mostly worked for me, Xcode got all upset and said automatic provisioning couldn't resolve issues with the entitlements file. I don't think it liked the variable.

Our solution was to:

  1. Enable all app groups on every target that needed access.

Enable all app groups

  1. Define a project-level user-defined setting called PROJECT_APP_GROUP for the app group name by going to Project -> Build Settings, clicking the "+" button, and selecting "Add User-Defined Setting."

User-Defined PROJECT_APP_GROUP setting

  1. Set a variable in the info.plist file for each target that needs access to your app group.

enter image description here

  1. Then access the correct app group at runtime by getting the APP_GROUP variable from your target's info.plist file.

    + (NSString *)appGroupIdentifier
    {
        // this method returns the app group identifier by fetching it from the info.plist file.
        // this string is dynamic based on build scheme. for instance group.ourApp vs. group.ourApp-dev
        return [[[NSBundle mainBundle] infoDictionary] valueForKey:@"APP_GROUP"];
    }
    

OR

Now that I think of it, if you have preprocessor macros set up for each build, it might be easier to do something like:

+ (NSString *)appGroupIdentifier
{
#ifdef BUILD_DEV
    return @"group.myApp-dev";
#elif BUILD_STAGING
    return @"group.myApp-staging";
#else
    return @"group.myApp";
#endif
}
like image 25
Dylan Hand Avatar answered Oct 21 '22 02:10

Dylan Hand