CoreMIDI/PGMidi Virtual midi error in iOS6

社会主义新天地 提交于 2019-12-05 17:16:00

问题


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;
    }
}

回答1:


[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>



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/12548856/coremidi-pgmidi-virtual-midi-error-in-ios6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!