CoreMIDI / PGMidi iOS6中的虚拟MIDI错误

前端之家收集整理的这篇文章主要介绍了CoreMIDI / PGMidi iOS6中的虚拟MIDI错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
面对两个错误.

这个代码在iOS 4和5中工作,但更新到6后,它不工作(

我发现以下,但不知道如何解决它在代码中.

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

2012-09-23 03:40:04.773 MidiStudio [1017:907]错误(创建MIDI虚拟源):-10844:错误域= NSMachErrorDomain代码= -10844“操作无法完成(Mach error -10844. )”

2012-09-23 03:40:04.777 MidiStudio [1017:907]错误(创建MIDI虚拟目的地):-10844:错误域= NSMachErrorDomain代码= -10844“操作无法完成(Mach error -10844. )”

这里是’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;
    }
}

解决方法

[把我的笔记放在库尔特的优秀答案上.]

首先,这一切都在文档中被称为“iOS 6.0发行说明”.那条线说:

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).

所以你唯一需要做的(再次,只是指出Kurt回答)在每个目标的主张是这样的:

<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
</array>
原文链接:https://www.f2er.com/iOS/329699.html

猜你在找的iOS相关文章