Xcode 中的每个配置应用程序组权利字符串?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25586605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:27:19  来源:igfitidea点击:

Per configuration app group entitlement strings in Xcode?

iosxcodeios8xcode6

提问by EricS

Is there an easy way to have per-configuration app group entitlement strings in Xcode projects?

有没有一种简单的方法可以在 Xcode 项目中拥有每个配置的应用程序组权利字符串?

We're trying to share settings between an iOS application and today extension using an "app group" entitlement in both the targets.

我们正在尝试使用两个目标中的“应用程序组”权利在 iOS 应用程序和今天的扩展程序之间共享设置。

The problem we're having is that we build the application with different bundle and team ids depending on whether it's an enterprise or a release build.

我们遇到的问题是,根据是企业版还是发布版,我们使用不同的捆绑包和团队 ID 构建应用程序。

When I use Xcode 6's Capabilities screen, the app groups show up in red lettering and I don't see a way to change the strings for each configuration individually.

当我使用 Xcode 6 的 Capabilities 屏幕时,应用程序组以红色字体显示,我没有看到单独更改每个配置的字符串的方法。

I assume one of the following will work, but I don't know which I should try first:

我认为以下方法之一会起作用,但我不知道我应该先尝试哪个:

  1. .xcconfig files
  2. Manually created entitlement files
  3. Build script
  4. Configuration-dependent plist entries
  1. .xcconfig 文件
  2. 手动创建的权利文件
  3. 构建脚本
  4. 依赖于配置的 plist 条目

Suggestions?

建议?

回答by quellish

You can use a different entitlements file for each configuration. This can be specified in the Xcode "Build Settings" user interface, or done through build configuration files (.xcconfig).

您可以为每个配置使用不同的权利文件。这可以在 Xcode“构建设置”用户界面中指定,或通过构建配置文件 (.xcconfig) 完成。

Example xcconfig:

示例 xcconfig:

CODE_SIGN_ENTITLEMENTS = Debug.entitlements

CODE_SIGN_ENTITLEMENTS = Debug.entitlements

Where the value for CODE_SIGN_ENTITLEMENTSpoints to the correct entitlements file for this configuration. You can create as many configurations as you want in Xcode. By default Xcode creates Debug and Release, you may add Enterprise and use a build configuration file which points CODE_SIGN_ENTITLEMENTSto the correct entitlements file for Enterprise builds.

其中 for 的值CODE_SIGN_ENTITLEMENTS指向此配置的正确权利文件。您可以在 Xcode 中创建任意数量的配置。默认情况下,Xcode 创建 Debug 和 Release,您可以添加 Enterprise 并使用构建配置文件,该文件指向CODE_SIGN_ENTITLEMENTSEnterprise 构建的正确授权文件。

The Xcode "Capabilities" user interface will create and manage an entitlements file that is named after your build product. You can edit this file directly if you desire.

Xcode“功能”用户界面将创建和管理一个以您的构建产品命名的权利文件。如果需要,您可以直接编辑此文件。

  1. Create an XCConfig build configuration file for each of your build configurations. For this example we will just use Debug and Release, it's simple to add your own build configurations such as Enterprise.
  2. As described above, populate the xcconfig files with the appropriate CODE_SIGN_ENTITLEMENTSsettings.
  3. In the Project "Info" user interface, set the build configuration to use the appropriate XCConfig file:
  1. 为每个构建配置创建一个 XCConfig 构建配置文件。对于本示例,我们将仅使用 Debug 和 Release,添加您自己的构建配置(例如 Enterprise)很简单。
  2. 如上所述,使用适当的CODE_SIGN_ENTITLEMENTS设置填充 xcconfig 文件。
  3. 在项目“信息”用户界面中,设置构建配置以使用适当的 XCConfig 文件:

enter image description here

在此处输入图片说明

  1. You can confirm by looking at the Code Signing Entitlements build setting for your build product. You should see something like this:
  1. 您可以通过查看构建产品的代码签名权利构建设置来确认。您应该会看到如下内容:

enter image description here

在此处输入图片说明

If you see boldtext there, highlight that build setting and hit delete. This will remove the Xcode build setting that is overriding your xcconfig setting.

如果您在那里看到粗体文本,请突出显示该构建设置并点击delete。这将删除覆盖 xcconfig 设置的 Xcode 构建设置。

回答by Mark Dominick Flores

You can setup this via the "Build Settings". Same way as setting up different bundle ids.

您可以通过“构建设置”进行设置。与设置不同的 bundle id 的方法相同。

Steps:

脚步:

  1. Add a new "User-Defined Setting"enter image description here
  2. Specify the "APP_GROUP_ID"for each scheme/config enter image description here
  3. Test it out, create an IPA for your app and unzip it.
  4. Check out the .app and right click then choose "Show Package Contents"
  5. Look for entitlements file. (if incase you can't find the entitlements file look for .xcentfile and change the extension to .entitlements
  6. Validate if the app group value in the entitlements file is the correct app group id you specified on step 2.
  1. 添加新的“用户定义设置”在此处输入图片说明
  2. 为每个方案/配置 指定“APP_GROUP_ID”在此处输入图片说明
  3. 测试一下,为您的应用程序创建一个 IPA 并解压缩它。
  4. 查看 .app 并右键单击然后选择“显示包内容”
  5. 查找权利文件。(如果您找不到权利文件,请查找.xcent文件并将扩展名更改为.entitlements
  6. 验证权利文件中的应用程序组值是否是您在步骤 2 中指定的正确应用程序组 ID。

Cheers!

干杯!

回答by Peter Lamberg

Xcode 8 seems to have a bug as the comments in this question indicate.

正如此问题中的评论所示,Xcode 8 似乎有一个错误。

I think I have a very rough and dangerous, but working workaround.

我想我有一个非常粗糙和危险但可行的解决方法。

The idea is to have just 1 entitlements file that Xcode 8 sees and have a script replace it with the correct file for the configuration you are trying to build.

这个想法是只有 1 个 Xcode 8 看到的权利文件,并有一个脚本将它替换为您尝试构建的配置的正确文件。

This workaround has many steps and not all of them may be necessary. I will try to update this post as more information is obtained. If you dare to test something like this, please add comments.

此解决方法有许多步骤,并非所有步骤都是必需的。随着获得更多信息,我将尝试更新这篇文章。如果你敢测试这样的东西,请添加评论。

Additionally old provisioning profiles probably need to be deleted before reopening Xcode 8.

此外,在重新打开 Xcode 8 之前,可能需要删除旧的配置文件。

Deleting derived data before opening Xcode 8 also seems to help.

在打开 Xcode 8 之前删除派生数据似乎也有帮助。

WARNING! TEST THIS AT YOUR OWN RISK. THIS CAN DO IRREVOCABLE DAMAGE

警告!请自担风险进行测试。这会造成不可挽回的损害

  • deletes all provisioning profiles
  • deletes DerivedData
  • 删除所有配置文件
  • 删除派生数据

SETTING UP THIS HACK

设置这个黑客

  • Save this script below to your project folder.
  • Patch in your project name and target names where it reads MyProject*
  • patch in your configuration names
  • Check the per configuration entitlements file names this script tries to copy on top of MyProject.entitlements
  • Configure MyProject.entitlements as entitlements file in all configurations
  • Do the same for all targets (if you have eg. watchkit app)
  • Before running the script:
    • Choose the correct Scheme in Xcode
    • Close Xcode
  • 将此脚本保存到您的项目文件夹中。
  • 在您的项目名称和目标名称中打上补丁 MyProject*
  • 修补您的配置名称
  • 检查此脚本尝试在 MyProject.entitlements 之上复制的每个配置权利文件名
  • 在所有配置中将 MyProject.entitlements 配置为权利文件
  • 对所有目标执行相同操作(如果您有 watchkit 应用程序)
  • 在运行脚本之前:
    • 在 Xcode 中选择正确的 Scheme
    • 关闭 Xcode

The script template:

脚本模板:

    #!/bin/bash                                                                                                                                                                                                                       

    echo

    if [ ! -n "$BASH" ] ;then echo Please run this script ##代码## with bash; exit 1; fi

    if [ $# -ne 1 ];  then
        echo
        echo "ERROR: one of the following expected as parameter: release alpha debug"
        echo
        exit -2
    fi

    chosen=

    echo "You have chosen build configuration $chosen"
    echo
    echo "This script is a workaround for Xcode 8 bug in handling different build configs and app groups."
    echo "(This scenario is most likely not on Apples list of things that developers are expected to do.)"
    echo
    echo "See comments in this SO answer"
    echo "http://stackoverflow.com/a/25734318/1148030"
    echo
    echo "1) This script must be run with Xcode 8 shut down."
    echo "2) All old provisioning profiles will be deteled. Xcode 8 will recreate them with hopefully correct build config."
    echo
    echo
    echo "WARNING: This will delete ALL provisioning profiles for all apps!"
    echo "WARNING: This will delete ALL MyProject named DerivedData."
    echo

    read -n 1 -s -p "Press any key to continue or Ctrl-C to cancel"

    echo

    # NOTE ABOUT DELETING DERIVED DATA                                                                                                                                                                                                
    # Deleting derived data fixes 2 bugs:                                                                                                                                                                                             
    # 1) Xcode 8 stubbornly generating some distribution profiles for old entitlements files                                                                                                                                          
    # 2) Install from HockeyApp fails due to signing verification error                                                                                                                                                               

    echo "Deleting derived datas"
    rm -vrf /Users/pelam/Library/Developer/Xcode/DerivedData/MyProject-*
    echo

    echo "Deleting provisioning profiles"
    rm -v ~/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision

    echo

    echo "Replacing target entitlements files"
    echo
    cp -v "./MyProjectTarget/MyProjectTarget.$chosen.entitlements" "./MyProjectTarget/MyProjectTarget.entitlements" || exit -1
    cp -v "./MyProjectAnotherTarget/MyProjectAnotherTarget.$chosen.entitlements" "./MyProjectAnotherTarget/MyProjectAnotherTarget.entitlements" || exit -1
    echo ADD COPY COMMANDS FOR OTHER TARGETS HERE

    echo
    echo "SUCCESS! Now run Xcode and verify that correct profiles are created."
    echo
    echo "NOTE:"
    echo "Running following command after starting Xcode 8 and waiting a bit can show you what appgroup is selected in each profile."
    echo "There should only the one correct app group or the release group. No duplicates in one file or mixed."
    echo "If you are not using multiple app groups, you can view the provisioning profile files in text editor to see that they contain correct settings for the configuration you are trying to build"
    echo "grep -a appgroup ~/Library/MobileDevice/Provisioning\ Profiles/*.mobileprovision"
    echo
    echo