I am able to create a midiclient via MIDIClientCreate when the scheme is a 64 bit processor (iPhone 5 and later). It does not work for 32 bit processors e.g. iPhone 4s.
#if !arch(arm64) || !arch(x86_64)
var status = OSStatus(noErr)
var s:CFString = "MyClient"
var client : Unmanaged<MIDIClient>?
status = MIDIClientCreate(s,
MIDINotifyProc( COpaquePointer( [ MyMIDINotifyProc ] ) ),
nil,
&client)
if status == OSStatus(noErr) {
if let c = client {
var val = c.takeRetainedValue()
Blammo. Bad access exception on takeRetainedValue. As you see, the status is OK, and I'm unwrapping the optional.
Do you have any suggestions?
In case you're wondering, for 64 bit processors, it's a lot simpler because you can just initialize the client var. Look at MIDIServices.h and you'll see that MIDICLient is defined differently for different processors.
var client = MIDIClientRef()
status = MIDIClientCreate(s,
MIDINotifyProc( COpaquePointer( [ MyMIDINotifyProc ] ) ),
nil,
&client)