Optional Framework Not Working (CoreAudioKit not on Simulator)

coremidi, ios, ios-simulator

Solution

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

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
}

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.

Update

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.

Other References

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

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

Problem

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. - Making the framework "optional" doesn't help, error is `ld: framework not found CoreAudioKit` I think it should work according to the docs - Deleting the framework allows my code to compile 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 ``` How can I get this optional compilation to work?

Original source

Related problems