本文介绍了iOS6中的CoreMIDI/PGMidi虚拟Midi错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到两个错误.

此代码在iOS 4和5中有效,但在更新到6后,它不起作用(

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.

从iOS 6开始,应用程序需要在其UIBackgroundModes中具有音频键,才能使用CoreMIDI的MIDISourceCreate和MIDIDestinationCreate函数.如果没有设置键,这些函数将返回kMIDINotPermitted(-10844).

2012-09-23 03:40:04.773 MidiStudio [1017:907]错误(创建MIDI虚拟源):-10844:Error Domain = NSMachErrorDomain代码= -10844操作无法完成.(机器错误-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]错误(创建MIDI虚拟目标):-10844:Error Domain = NSMachErrorDomain代码= -10844操作无法完成.(错误机器-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.)"

以下是源"的代码:

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

推荐答案

[只要在Kurt的出色回答中写下我的笔记即可.]

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

首先,在名为"iOS 6.0发行说明"的文档中提到了所有这些内容.那里的行说:

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

因此,您唯一需要做的事情(同样,只需指定Kurt回答的内容)就是每个目标的plist 中的内容:

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>

这篇关于iOS6中的CoreMIDI/PGMidi虚拟Midi错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:07