CoreMIDI/PGMidi Virtual midi error in iOS6

coremidi, midi, virtual

Solution

[Just putting my notes here on Kurt's excellent answer.]

First off, this is all mentioned in the document called "iOS 6.0 Release Notes." The line there says:

Beginning in iOS 6, apps need to have the audio key in their UIBackgroundModes in order to use CoreMIDI’s MIDISourceCreate and MIDIDestinationCreate functions. Without the key set, these functions will return kMIDINotPermitted (-10844).

So the only thing you need to do (again, just specifying what Kurt answered) is something like this in each target's plist:

<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
</array>

Problem

Faced with two errors. This code worked in iOS 4 and 5, but after update to 6, it is not working ( I found following, but don't know how to fix it in the code. Beginning in iOS 6, apps need to have the audio key in their UIBackgroundModes in order to use CoreMIDI’s MIDISourceCreate and MIDIDestinationCreate functions. Without the key set, these functions will return kMIDINotPermitted (-10844). 2012-09-23 03:40:04.773 MidiStudio[1017:907] Error (Create MIDI virtual source): -10844:Error Domain=NSMachErrorDomain Code=-10844 "The operation couldn’t be completed. (Mach error -10844.)" 2012-09-23 03:40:04.777 MidiStudio[1017:907] Error (Create MIDI virtual destination): -10844:Error Domain=NSMachErrorDomain Code=-10844 "The operation couldn’t be completed. (Mach error -10844.)" Here is code for 'source': ``` -(void)setVirtualSourceEnabled:(BOOL)virtualSourceEnabled { if ( virtualSourceEnabled == self.virtualSourceEnabled ) return; if ( virtualSourceEnabled ) { NSString *name = virtualEndpointName ? virtualEndpointName : [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString*)kCFBundleNameKey]; OSStatus s = MIDISourceCreate(client, (CFStringRef)name, &virtualSourceEndpoint); NSLogError(s, @"Create MIDI virtual source"); if ( s != noErr ) return; virtualSourceDestination = [[PGMidiVirtualSourceDestination alloc] initWithMidi:self endpoint:virtualSourceEndpoint]; [delegate midi:self destinationAdded:virtualSourceDestination]; [[NSNotificationCenter defaultCenter] postNotificationName:PGMidiDestinationAddedNotification object:self userInfo:[NSDictionary dictionaryWithObject:virtualSourceDestination forKey:PGMidiEndpointKey]]; } else { [delegate midi:self destinationRemoved:virtualSourceDestination]; [[NSNotificationCenter defaultCenter] postNotificationName:PGMidiDestinationRemovedNotification object:self userInfo:[NSDictionary dictionaryWithObject:virtualSourceDestination forKey:PGMidiEndpointKey]]; [virtualSourceDestination release]; virtualSourceDestination = nil; OSStatus s = MIDIEndpointDispose(virtualSourceEndpoint); NSLogError(s, @"Dispose MIDI virtual source"); virtualSourceEndpoint = NULL; } } ```

Original source