如何在iOS SDK中创建伞架? [英] How to create an umbrella framework in iOS SDK?

查看:112
本文介绍了如何在iOS SDK中创建伞架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS SDK中创建一个伞形框架。我的要求是:

我有一个名为Framework A的框架,我想创建另一个名为Framework B的框架。我想将框架A作为子框架添加到框架B中,用户只需要在其项目中导入框架B以同时使用框架A和框架B。换句话说,框架B将作为框架A的包装。我通过以下关于框架创作的链接从Apple中读出: Conceptual / BPFrameworks / Concepts / FrameworkAnatomy.htmlrel =noreferrer> https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html



但它没有揭示创建伞架的方式。



请逐步建议创建一个伞形框架。

解决方案

我们都知道,创建伞架非常受到苹果公司的阻挠。但苹果也表示可以通过Xcode。 https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/CreationGuidelines.html#//apple_ref/doc/uid/20002254-BAJHGGGA



我通过Xcode 5.1上的这些简单方法实现了创建伞架。我们只需要关注一些特殊的配置,将子框架与伞形框架连接起来。这里是我的方法: - 在这里描述的方法中,在Xcode 5.1上安装real Static iOS Framework

- https://github.com/kstenerud/iOS-Universal-Framework



现在可以使用Xcode中的新选项创建'静态iOS框架'。

静态iOS框架并更改目标 - >生成设置 - > Architectures->体系结构设置为标准体系结构。这将创建具有所有标准体系结构的框架。



目标 - >中的公共头文件。构建阶段 - >复制标题。我们可以在这里设置头文件的可视性。





4)将SubFramework链接到目标 - >构建阶段 - >链接二进制与库。我们可能还需要链接其他标准框架,具体取决于我们的用途。






5)我们可能还需要在 Target->中添加Bundle资源。构建阶段 - >如果需要的话,复制Bundle资源



-ObjC 添加到<$>
< C $ C>靶>构建设置 - >链接 - >其他链接标志,因为我们可能需要加载一个大型子框架,其中有很多类别需要加载或需要加载额外的框架。





7)添加复制文件使用目标 - >构建阶段 - > + - >新复制文件构建阶段



Frameworks 并在其中添加SubFramework.framework。这将复制SubFramework到Umbrella Framework。






< 9)对于演示我在UmbrellaFramework类中添加了两个演示方法。一个用来演示伞形框架方法调用,另一个用于调用子框架方法。






10)从菜单 - >产品 - >存档中选择 iOS设备并归档UmbrellaFramework项目C $ C>。这将创建我们的伞架,这就是全部。





11)现在是时候创建一个新的演示项目,并将其与UmbrellaFramework链接。




12)只需导入UmbrellaFramework标题并调用两个方法即可。它会在日志窗口中显示Hello消息。




I want to create an umbrella framework in iOS SDK. My requirements are:

I have a framework called "Framework A", I want to create another framework called "Framework B". I want to add "Framework A" into "Framework B" as a sub-framework and users only need to import "Framework B" in their project to use both "Framework A" and "Framework B". In other words, "Framework B" will work as a wrapper for "Framework A". I read out from Apple via following link regarding framework creations:

https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html

but it doesn't expose the way to create an umbrella framework.

Please suggest step by step method to create an umbrella framework.

解决方案

We all know that creating umbrella framework is highly discouraged by Apple. But apple also says it’s possible via Xcode. https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/CreationGuidelines.html#//apple_ref/doc/uid/20002254-BAJHGGGA

I achieved creating umbrella framework via these simple approach on Xcode 5.1. We just need to do take care of some special configuration to linking sub-framework to umbrella framework. Here was my approach:-

1) Install real Static iOS Framework on Xcode 5.1 from the method described here:- https://github.com/kstenerud/iOS-Universal-Framework.

Now the ‘Static iOS Framework’ can be created using the new option in Xcode.

2) Create a Static iOS Framework and change the Target-> Build Settings-> Architectures-> Architectures settings to Standard architectures. This will create the framework with all the Standard Architectures.

3) Adjust Public Header files in Target-> Build Phase-> Copy Headers. We can set the header file visibility here.

4) Link SubFramework to UmbrellaFramework in Target->Build Phase -> Link Binary With Libraries. We may also need to link other standard framework depending on our use.

5) We may also need to add Bundle Resources in Target-> Build Phase-> Copy Bundle Resources if we need.

6) We may also need to add -ObjC to Target-> Build Settings->Linking-> Other Linker Flag, as we may need to load a large subFramework where there are many categories to load or need to load additional frameworks also.

7) Add Copy File using Target-> Build Phases-> +-> New Copy File Build Phase.

8) Change it’s Destination to Frameworks and add SubFramework.framework there. This will copy SubFramework to Umbrella Framework.

9) For the demo I Added two demo methods in UmbrellaFramework class. One to demonstrating umbrella framework method call and one for calling subFramework method.

10) Select iOS Device and Archive the UmbrellaFramework project from Menu->Product->Archive. This will create our umbrella framework and that’s all.

11) Now it’s time to create a new demo project, and link it with UmbrellaFramework.

12) Just import UmbrellaFramework header and call the two methods. It will show the Hello messages in log window.

这篇关于如何在iOS SDK中创建伞架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆