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

时间:2014-08-30 20:44:15

标签: ios xcode ios8 xcode6

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

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

我们遇到的问题是,我们使用不同的捆绑和团队ID构建应用程序,具体取决于它是企业还是发布版本。

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

我认为以下其中一项可行,但我不知道应该先尝试哪一项:

  1. .xcconfig files
  2. 手动创建的权利文件
  3. 构建脚本
  4. 与配置相关的plist条目
  5. 建议?

3 个答案:

答案 0 :(得分:21)

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

示例xcconfig:

CODE_SIGN_ENTITLEMENTS = Debug.entitlements

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

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

  1. 为每个构建配置创建一个XCConfig构建配置文件。对于这个例子,我们将只使用Debug和Release,添加自己的构建配置很简单,例如Enterprise。
  2. 如上所述,使用适当的CODE_SIGN_ENTITLEMENTS设置填充xcconfig文件。
  3. 在Project“Info”用户界面中,将构建配置设置为使用相应的XCConfig文件:
  4. enter image description here

    1. 您可以通过查看构建产品的代码签名权利构建设置进行确认。你应该看到这样的东西:
    2. enter image description here

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

答案 1 :(得分:5)

您可以通过"构建设置"进行设置。与设置不同的捆绑ID相同。

步骤:

  1. 添加新的 "用户定义的设置" enter image description here
  2. 为每个方案/配置指定 " APP_GROUP_ID" enter image description here
  3. 测试一下,为您的应用创建一个IPA并解压缩。
  4. 查看.app并右键单击,然后选择 "显示包内容"
  5. 查找权利文件。 (如果您无法找到权利文件,请查找 .xcent 文件,并将扩展名更改为 .entitlements
  6. 验证权利文件中的应用组值是否是您在步骤2中指定的正确的应用组ID。
  7. 干杯!

答案 2 :(得分:0)

Xcode 8似乎有一个错误,因为此问题中的评论表明。

我认为我有一个非常粗暴和危险但工作的解决方法。

我们的想法是只拥有Xcode 8所看到的1个权利文件 有一个脚本将其替换为配置的正确文件 你正在努力建设。

此解决方法有许多步骤,并非所有步骤都可能是必需的。 我将尝试更新此帖子,因为获得了更多信息。 如果你敢于测试这样的东西,请添加评论。

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

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

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

  • 删除所有配置文件
  • 删除DerivedData

设置这个黑色

  • 将此脚本保存到项目文件夹中。
  • 修补项目名称和目标名称,其中包含MyProject *
  • 配置名称中的补丁
  • 检查此脚本尝试在MyProject.entitlements上复制的每个配置权利文件名
  • 在所有配置中将MyProject.entitlements配置为权利文件
  • 对所有目标执行相同操作(如果您有例如.watchkit app)
  • 在运行脚本之前:
    • 在Xcode中选择正确的Scheme
    • 关闭Xcode

脚本模板:

    #!/bin/bash                                                                                                                                                                                                                       

    echo

    if [ ! -n "$BASH" ] ;then echo Please run this script $0 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=$1

    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