iOS Static vs Dynamic frameworks clarifications

I have to admit that with the release of iOS 8 I am a bit confused about dynamic and static frameworks in iOS.

I am looking for a way to distribute a library that I created, and I need to support iOS 7 and above. (Note: This will be a proprietary framework. I cannot use cocoa pods, and I also cannot distribute the source). Here is what I already know:

  • iOS 8 introduced "embedded frameworks" for iOS, but, as I understand, they do not work for iOS 7, only for iOS 8 and above.
  • I have the option of distributing my library as a static library (.a file) and also distribute the headers. I know that this is a common way of dealing with the situation, but I would like to find something simpler than that (and also to bundle some resources with it, if possible).
  • I have also found that iOS 7 does not support dynamic .framework libraries (only static) because it doesn't support dynamic linking. But iOS 8 does, as well as static linking.

And here are my questions regarding this information:

  • I saw that I can create a .framework target, and make it static, by changing the Mach-O type to "static library. Would that be enough in order to support iOS 7 without any problems, and also to distribute my library as a .framework bundle? If so, why is "embedded frameworks" in iOS 8 that big of a deal, as many resources on the internet are suggesting? Am I missing something?
  • Is it necessary to codesign the .framework just as I do with any other application I make?
  • What if I need to include other resources (like Core Data or Images) with my .framework file? Will I need to make a separate .bundle file for that?
45054 次浏览

我不知道所有问题的答案,但我会试着回答你们的一些问题。

  • 在 iOS7中使用这些框架会得到一个警告,不过仅此而已,只是一个警告。看这个 回答

  • 您可以包含其他资源,比如 CoreData,但是您需要在代码中手动创建它们。下面的 教程展示了如何创建核心数据模型。

  • You have to code sign dynamic libraries for iOS.

  • 如果计划分发框架,则需要确保框架同时支持模拟器和设备体系结构。

在 iOS8之前,Xcode 只允许为 iOS 创建静态库。这样做的共同问题是,我们必须分别发送二进制文件和头文件。

后来,一些开发人员提出了创建“静态框架”的想法。[环境影响评估报告]。Framework 只是一个文件夹,其中包含到库和标题的符号链接]。https://github.com/jverkoey/iOS-Framework就是这样一个例子

这个选项适用于 iOS7或8或更早的版本。因为它们只是静态库,可以方便地将头文件捆绑在一起。

至于你关于资源的问题,我们需要把它们捆绑在一起。捆绑。.关于运输,我不确定我们是否可以把它们附在。框架文件夹。.在过去,我常常将我的 libs 作为一个静态框架和 bundle 发布..。

但是,如果您使用 Swift,上面的选项将不起作用。Xcode 不支持构建包含快速代码的静态库。

You must go with Dynamic frameworks if there is swift usage. In theory, Dynamic frameworks work in iOS7.. But, i think iTunes Connect will reject if the app is targeting iOS7 and uses Dynamic frameworks :-).

Hope this helps

Swift 在静态 lib 中不起作用。如果必须使用动态框架,则必须将 min iOS 设置为8.0 因为 AppStore 拒绝 Ios7动态框架

从 Xcode 9开始,你也可以为 Swift 创建静态框架。这是可能的,因为 ABI 源兼容性。您所需要做的只是在框架目标的构建设置下更改 Mach-O type。 这种技术也适用于混合框架(包含 Swift 和 Objective-C 代码的框架)。

静态链接与动态链接

static or dynamic in name usually points into a Linking< sup > [ About ] type

框架可以是 staticdynamic[检查静态或动态]

通过将 Framework target -> Build Settings -> Mach-O Type< sup > [ About ] 更改为 Static LibraryDynamic Library,可以更改将对 Linker产生影响的库的格式。默认情况下,Xcode 具有 Dynamic Library值。

根据这个设置,将生成不同类型的二进制文件

成功配置 consumer[Link vs Embed]之后

Static Linker : 在 编译时将包括所有代码从 static library到可执行对象文件。

Dynamic Linker Dyld: 在加载/运行时将尝试使用 @rpath< sup > [ About ] 找到嵌入式框架并链接它

[Vocabulary]