iOS 8 Bluetooth MIDI LE build tip
iOS Bluetooth MIDI LE
Introduction
iOS 8 and OS X Yosemite now supports sending and receiving MIDI data using Bluetooth Low Energy connections on any iOS device or Mac that has native Bluetooth Low Energy support.
I reminding myself here of a simple problem I had that wasted my time.
The Bluetooth classes
So, I’m playing around with the new Bluetooth LE MIDI capabilities.
Im my build settings I include the CoreAudioKit framework in order to get
the new Core Audio Bluetooth MIDI (CABTMIDI) controllers CABTMIDILocalPeripheralViewController and CABTMIDICentralViewController.
You also get the Inter-App audio classes CAInterAppAudioSwitcherView and CAInterAppAudioTransportView with CoreAudioKit, but I’m not using them here.
Here is a very simple view controller example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import UIKit import CoreAudioKit import CoreMIDI class ViewController: UIViewController { var localPeripheralViewController:CABTMIDILocalPeripheralViewController? var centralViewController:CABTMIDICentralViewController? override func viewDidLoad() { super.viewDidLoad() localPeripheralViewController = CABTMIDILocalPeripheralViewController() centralViewController = CABTMIDICentralViewController() } @IBAction func someAction(sender: AnyObject) { self.navigationController?.pushViewController(localPeripheralViewController!, animated: true) } @IBAction func midiCentral(sender: AnyObject) { self.navigationController?.pushViewController(centralViewController!, animated: true) } } |
I played around with it, then had to do other work. I came back to it a week later, and it wouldn’t even compile. I didn’t change anything (e.g. no XCode updates). Yes, the CoreAudioKit is indeed included, but the error was one the “import CoreAudioKit”. The compiler didn’t know what that was even though the framework is there and I can even see the headers in the XCode UI tree under CoreAudioKit.framework.
It turns out that the build scheme needs to have a device selected, and not any of the simulator choices. Even if you are building and not running. The device does not need to be attached. You can just choose the first item: iOS Device. Then it will build.
D’Oh!
Apple even says so in a tech note (that I did not know existed). See the resources below.
Summary
Bluetooth LE MIDI support will build only if a device is selected.