ios - 可选框架不工作(CoreAudioKit 不在模拟器上)

标签 ios ios-simulator coremidi

要通过蓝牙运行 MIDI,我需要使用 CoreAudioKit 框架。这非常有效,但我无法在模拟器上编译。

  1. 将框架设为“可选”没有帮助,错误是 ld: framework not found CoreAudioKit

enter image description here

我认为它应该根据 the docs 工作

  1. 删除框架允许我的代码编译

我在代码中得到了这个,这就是为什么我可以毫无问题地删除框架。

#if !TARGET_IPHONE_SIMULATOR
#import <CoreAudioKit/CoreAudioKit.h>
#endif


我怎样才能让这个可选的编译工作?

最佳答案

我本来以为这行得通,但我认为您可以用另一种方式解决它。这对我有用:

  1. 在您的目标设置构建阶段中删除对 CoreAudioKit 的所有引用(将二进制文件与库链接)

  2. 确保没有手动输入类似的设置。例如,不要在 Other Linker Flags

    中添加此设置:-weak_framework CoreAudioKit
  3. 使用预处理器标志为模拟器有条件地编译代码:

#import "ViewController.h"

#if !TARGET_IPHONE_SIMULATOR
@import CoreAudioKit;
#endif

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
   [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.

#if !TARGET_IPHONE_SIMULATOR
   if ([CABTMIDICentralViewController class]) {   // maybe not needed?
      CABTMIDICentralViewController *vc = [[CABTMIDICentralViewController alloc] init];
   }
#endif
}

注意:在我上面的示例中,您可能需要测试 CABTMIDICentralViewController 类是否存在。这取决于您的应用是仅针对 iOS 8+ 还是同时针对 iOS 7。

更新

根据@Yar 和@JeremyHuddlestonSequoia 下面的评论,请注意此解决方案要求您在项目build设置中启用模块自动链接框架。这些 Xcode 设置现在默认为该技术的正确值,但如果您正在管理一个较旧的项目,请确保它们已启用。

其他引用资料

https://stackoverflow.com/a/26510640/119114

https://stackoverflow.com/a/25883210/8047

关于ios - 可选框架不工作(CoreAudioKit 不在模拟器上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31574430/

相关文章:

swift - Swift 中的 CoreMIDI 回调

iOS CoreMIDI 跳过 MidiPackets

iphone - 如何将二进制数据转换为 NSData

jquery - 组合 jQuery 函数

ios - 是否可以在不停止之前任务的情况下同时使用多个模拟器进行调试?

ios-simulator - TVMLKitErrorDomain 错误 3 消息

iphone - 将导航 Controller 添加到 UIViewController

iphone - 如何将 UIView 移到其 SuperView 之外?

ios - 如何修复 Xcode "DTAssetProviderService could not start.."错误?