Xcode 8: different entitlements for each scheme causing errors

谁说我不能喝 提交于 2019-11-28 23:45:49

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.

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.

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

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

  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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!