xcode 在框架中嵌入框架(iOS 8+)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27868259/
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 06:28:05  来源:igfitidea点击:

Embedding a framework within a framework (iOS 8+)

iosxcodecocoadynamicframeworks

提问by Vatsal Manot

iOS applications built with Xcode 6 or higher allow embedding dynamic iOS frameworks within them. I am building a shared framework and would like to embed a sub-framework. How can I accomplish this?

使用 Xcode 6 或更高版本构建的 iOS 应用程序允许在其中嵌入动态 iOS 框架。我正在构建一个共享框架并希望嵌入一个子框架。我怎样才能做到这一点?

Note: This ispossible and isbeing used in production (for e.g., with Swift frameworks in CocoaPods).

:这可能的,正在生产(在例如,用斯威夫特框架中使用的CocoaPods)。

采纳答案by Vatsal Manot

Found the answer. Here's how it's done:

找到了答案。这是它的完成方式:

  • Navigate to Target> Build Phases
  • Click the small "+" icon and select "New Run Script Build Phase"
  • Paste the following:

    cd $BUILT_PRODUCTS_DIR
    
    mkdir $PROJECT_NAME.framework/Frameworks &>/dev/null
    
    for framework in *.framework; do
        if [ $framework != $PROJECT_NAME.framework ]; then
            cp -r $framework $PROJECT_NAME.framework/Frameworks/ &>/dev/null
        fi
    done
    
  • 导航到目标>构建阶段
  • 单击小“+”图标并选择“New Run Script Build Phase”
  • 粘贴以下内容:

    cd $BUILT_PRODUCTS_DIR
    
    mkdir $PROJECT_NAME.framework/Frameworks &>/dev/null
    
    for framework in *.framework; do
        if [ $framework != $PROJECT_NAME.framework ]; then
            cp -r $framework $PROJECT_NAME.framework/Frameworks/ &>/dev/null
        fi
    done
    

回答by Justin Domnitz

@Vatsal Manot's answer was very helpful for me. I modified it a bit and also had a need to sign the copied embedded framework. My script is below.

@Vatsal Manot 的回答对我很有帮助。我稍微修改了一下,还需要对复制的嵌入式框架进行签名。我的脚本如下。

cd $BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Frameworks/Custom.framework/Frameworks
for framework in *.framework; do
    mv $framework $BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Frameworks/
    /usr/bin/codesign --force --sign "iPhone Developer" --preserve-metadata=identifier,entitlements --timestamp=none $BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app/Frameworks/$framework
done

回答by ehrpaulhardt

To create a Umbrella Framework that contains a Sub-Framework you can follow the step-by-step guide written down here: Umbrella framework

要创建包含子框架的 Umbrella 框架,您可以按照此处记下的分步指南进行操作:Umbrella 框架