要通过蓝牙运行 MIDI,我需要使用 CoreAudioKit
框架。这非常有效,但我无法在模拟器上编译。
- 将框架设为“可选”没有帮助,错误是
ld: framework not found CoreAudioKit
我认为它应该根据 the docs 工作
- 删除框架允许我的代码编译
我在代码中得到了这个,这就是为什么我可以毫无问题地删除框架。
#if !TARGET_IPHONE_SIMULATOR
#import <CoreAudioKit/CoreAudioKit.h>
#endif
我怎样才能让这个可选的编译工作?
最佳答案
我本来以为这行得通,但我认为您可以用另一种方式解决它。这对我有用:
在您的目标设置构建阶段中删除对 CoreAudioKit 的所有引用(将二进制文件与库链接)
确保没有手动输入类似的设置。例如,不要在 Other Linker Flags
中添加此设置:-weak_framework CoreAudioKit
使用预处理器标志为模拟器有条件地编译代码:
#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 设置现在默认为该技术的正确值,但如果您正在管理一个较旧的项目,请确保它们已启用。
其他引用资料
关于ios - 可选框架不工作(CoreAudioKit 不在模拟器上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31574430/