CoreMIDI/PGMidi Virtual midi error in iOS6
Asked Answered
K

3

10

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;
    }
}
Kiangsi answered 23/9, 2012 at 0:46 Comment(0)
T
14

[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>
Tetryl answered 25/9, 2012 at 15:17 Comment(1)
FYI, the user-friendly plist entry name is "Required background modes"Backfill
B
7

You don't need to change any code. Read that message again:

Beginning in iOS 6, apps need to have the audio key in their UIBackgroundModes

UIBackgroundModes is a key in your application's Info.plist. So use Xcode to edit your app's Info.plist, and make the value for that key be an array containing the string audio.

Bogbean answered 23/9, 2012 at 3:24 Comment(2)
Kurt is right. However...Apple may not let it pass without making a stink about it if your app doesn't play in the background. Just sight this and things will work out.Leffen
@Leffen eventually, you will have to justify yourself, even if your app has been selling in the store for years. UNLESS you never submit an update ;)Tetryl
C
1

My app uses the MIDIDestinationCreate to play a midi file and the app review team are indeed creating a stink. They insist that the app must play some audio in the background. They quote "2.16: Multitasking Apps may only use background services for their intended purposes: VoIP, audio playback, location, task completion, local notifications, etc."

I've referred them to the iOS6 release notes mentioned here and they just keep coming back saying it must play audio in the background.

I've submitted a request to Apple Developer Technical Support. Hopefully they will change the app review guidelines which their team follow.

Caoutchouc answered 18/7, 2014 at 16:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.