可选框架不起作用(CoreAudioKit 不在模拟器上)

2024-02-21

为了让 MIDI 通过蓝牙工作,我需要使用CoreAudioKit框架。这工作完美,但我无法在模拟器上编译。

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

我认为它应该按照the docs https://developer.apple.com/library/mac/recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html

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

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

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

How can I get this optional compilation to work?

我实际上以为这会起作用,但我认为你可以用另一种方式解决它。这对我有用:

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

  2. 确保没有手动输入类似的设置。例如,不要添加此设置:-weak_framework CoreAudioKit in the 其他链接器标志

  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
}

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

Update

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

其他参考资料

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

可选框架不起作用(CoreAudioKit 不在模拟器上) 的相关文章

随机推荐