可选框架不起作用(CoreAudioKit不在模拟器上) [英] Optional Framework Not Working (CoreAudioKit not on Simulator)

查看:344
本文介绍了可选框架不起作用(CoreAudioKit不在模拟器上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

To get MIDI over Bluetooth working, I need to use the CoreAudioKit framework. This works perfectly, but I am not able to compile on the simulator.


  1. 使框架可选没有帮助,错误是 ld:找不到框架CoreAudioKit

  1. Making the framework "optional" doesn't help, error is ld: framework not found CoreAudioKit

我觉得应该根据的文档工作


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

我在代码中有这个,这就是为什么我可以删除框架而没有问题。

I've got this in code, which is why I can delete the framework without issues.

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



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

推荐答案

我实际上会认为这样可行,但我认为你可以解决它其他方式。这对我有用:

I actually would have thought that would work, but I think you can solve it another way. This worked for me:


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

  1. remove all references to CoreAudioKit in your target settings Build Phases (Link Binary With Libraries)

确保手动输入的类似设置没有。例如,请勿在其他链接标记

make sure there's no similar settings entered in manually. for example, don't add this setting: -weak_framework CoreAudioKit in the Other Linker Flags

使用预处理程序标志有条件地编译模拟器的代码:

use preprocessor flags to conditionally compile your code for the simulator:





#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。

Note: in my example above, you might not need to test for the existence of the CABTMIDICentralViewController class. It depends on whether your app is targeting only iOS 8+, or also iOS 7.

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

Per comments below by @Yar and @JeremyHuddlestonSequoia, note that this solution requires you to Enable Modules and Link Frameworks Automatically in project build settings. These Xcode settings now default to the proper values for this technique, but in case you're managing an older project, make sure they're enabled.

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

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

这篇关于可选框架不起作用(CoreAudioKit不在模拟器上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆