1

有人可以确认这是否确实是一个错误?(如果是这样,我会去向 Apple 归档)。

尝试获取 kAudioSessionProperty_AudioRoute 在 4.3 之前的任何版本的模拟器上返回错误代码 kAudioSessionUnsupportedPropertyError(这是撰写本文时的最新版本)。

这个很容易复制。

启动一个新项目(我使用的是Xcode 4.0.2 Build 4A2002a,即标准构建),基于窗口的项目“AudioSessionBug”

包括 AudioToolbox 框架

将应用程序委托的 .m 文件替换为以下内容:

//
//  AudioSessionBugAppDelegate.m
//  AudioSessionBug
//
//  Created by Pi on 02/07/2011.
//  Copyright 2011 Pi. All rights reserved.
//

#import "AudioSessionBugAppDelegate.h"

#import <AudioToolbox/AudioToolbox.h>

#define SET_PROPERTY( prop, type, val ) \
{ \
OSStatus ret = AudioSessionSetProperty( prop, sizeof( type ), &(type){ val } ); \
if ( ret != kAudioSessionNoError ) \
{ \
NSLog( @"AudioSessionSETProperty failed for: %s!", #prop ); \
return; \
} \
}

enum  {
    kNo = 0,
    kYes = 1
};

// - - - 

@interface AudioSessionBugAppDelegate ( )

- (void) setupSession;

@end

// - - - 

@implementation AudioSessionBugAppDelegate


@synthesize window=_window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];


    [self setupSession];


    return YES;
}

- (void) setupSession
{
    OSStatus result = AudioSessionInitialize( NULL, NULL, NULL, NULL );
    assert( result == kAudioSessionNoError );

    SET_PROPERTY( kAudioSessionProperty_AudioCategory,  UInt32,   kAudioSessionCategory_PlayAndRecord );

    // make sure headphones are plugged in!
    {
        // http://stackoverflow.com/questions/2753562/what-kind-of-routes-could-i-get-back-from-kaudiosessionproperty-audioroute-proper
        CFStringRef state = nil;        
        UInt32 propertySize = sizeof(CFStringRef);
        OSStatus status = AudioSessionGetProperty( kAudioSessionProperty_AudioRoute, &propertySize, &state );

        if ( status == kAudioSessionUnsupportedPropertyError )
        {
            NSLog( @" WTF? GETTING kAudioSessionProperty_AudioRoute GIVES kAudioSessionUnsupportedPropertyError ?!?!? " );
        }

        NSLog( @" OK - done! " );

        exit( 1 );
    }
}

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

@end

检查它是否有效。

现在将部署目标更改为 4.3 之前的任何内容。说4.2。

在 iPad 模拟器 4.3 上再次运行它 - OK
在 iPad 模拟器 4.2 上再次运行它 - 失败

4

1 回答 1

1

我刚刚收到来自 Apple 的以下确认:

这是在 4.3 中修复的错误,我们目前没有计划修复早期版本的模拟器中的错误。

于 2011-07-16T02:42:34.803 回答