这个崩溃是一个阻塞问题,我使用以下步骤来重现这个问题:

创建一个Cocoa Touch框架项目 添加一个swift文件和一个类Dog 为设备构建一个框架 在Swift中创建一个单视图应用程序 导入框架到应用程序项目 从ViewController中的框架实例化swift类 在设备上构建并运行应用程序

应用程序在启动时立即崩溃,这是控制台日志:

dyld: Library not loaded: @rpath/FrameworkTest03.framework/FrameworkTest03
  Referenced from: /var/mobile/Applications/FA6BAAC8-1AAD-49B4-8326-F30F66458CB6/FrameworkTest03App.app/FrameworkTest03App
  Reason: image not found

I have tried to build on iOS 7.1 and 8.0 devices, they both have the same crash. However, I can build an app and run on the simulator fine. Also, I am aware that I can change the framework to form Required to Optional in Link Binary With Libraries, but it did not completely resolve the problem, the app crashed when I create an instance of Dog. The behavior is different on the device and simulator, I suspect that we can't distribute a framework for the device using a beta version of Xcode. Can anyone shed light on this?


当前回答

对于大于或等于8的iOS

在目标的General选项卡下,在Embedded Binaries部分中添加框架。这将把框架复制到编译后的文件中,以便在运行时可以链接到它。

为什么会这样?:因为你要链接的框架被编译为动态链接的框架,因此在运行时被链接。

**注意:**嵌入自定义框架只支持在iOS > 8,因此一个替代解决方案,适用于旧版本的iOS如下。

对于小于8的iOS

如果您影响了这个框架(可以访问源代码/构建过程),您可以将这个框架更改为静态链接而不是动态链接。这将导致代码包含在编译后的应用程序中,而不是在运行时链接到,因此框架将不必嵌入。

**方法:**在框架的Build Setting选项卡下,在链接部分,将Mach-O类型更改为静态库。您现在不需要将框架包含在嵌入式二进制文件中。

包含资产:为了包含图像、音频或xib/nib文件,我建议创建一个bundle(本质上是一个目录,更多信息在这里bit.ly/ios_bundle),然后使用NSBundle从bundle中加载资产。

其他回答

仅仅将框架拖到项目中是不够的。这就像是在同一个球场,却找不到自己的孩子。遵循以下步骤:

1)创建框架

开发框架。 一旦你的开发完成,COMMAND+B构建你的框架,并确保你收到“构建成功”。

2)访问你的框架

一旦你的框架项目成功构建,你就可以在项目的Products文件夹中访问它了。

右键单击你的.framework,选择“显示在Finder中”。

3)在项目中放置框架

将. Framework从Finder窗口拖放到应用项目的“Framework”文件夹中。

4)为框架配置app项目

选择项目中的顶层

选择目标

转到“Build Phases”,然后是“Link Binary with Libraries”,确保你的框架包含了可选选项。

仍然在“构建阶段”,转到左上角并选择+按钮。在下拉菜单中选择“New Copy Files Phase”。

向下滚动到新的“复制文件”部分,并确保您将目标设置为“框架”。将子路径保留为空。然后点击左下角的+按钮。

您将看到您的项目层次结构。向下滚动到第三步中添加框架的“Frameworks”文件夹,或者在顶部的搜索栏中搜索它。选择你的框架,然后点击“添加”。

确保选择了“代码签入复制”,并包含了您的框架。

5)清洁,然后运行你的项目

司令部SHIFT键+ K 指挥部+ R

After trying all the methods available on internet and my own trial and error tricks 100 times. Finally I was able to solve it. – Apeksha Sahu 6 mins ago Goto iTunes in Mac --> accounts-->Authorize this computer – Apeksha Sahu 5 mins ago second step.... Goto developer in settings in iPad and iPhone and reindex with identifiers and clear trust computers everything. It worked for me........ ....... After reinstalling Mac OSHigh seria 10.13.15 version from Mac OS seirra beta latest version, to reinstalling Xcode latest version, after updating all certificates. etc etc etc... as many methods as you can think I did. –

解决了为我取消选择“仅在安装时复制”在构建阶段->嵌入框架

如果有开发pod,从模拟器中删除应用程序,从pod中安装-> clean ->再次运行…

您需要将框架添加到一个新的Copy Files Build Phase,以确保框架在运行时被复制到应用程序包中。

有关更多信息,请参阅如何将“复制文件构建阶段”添加到我的目标。

官方苹果文档:https://developer.apple.com/library/mac/recipes/xcode_help-project_editor/Articles/CreatingaCopyFilesBuildPhase.html