Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreMIDI/PGMidi Virtual midi error in iOS6

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;
    }
}
like image 452
user1195202 Avatar asked Sep 23 '12 00:09

user1195202


1 Answers

[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>
like image 191
Dan Rosenstark Avatar answered Oct 20 '22 02:10

Dan Rosenstark