iOS: Is this an audio-session simulator bug? keywords: kAudioSessionProperty_AudioRoute kAudioSessionUnsupportedPropertyError
can someone confirm whether this is indeed a bug? ( If so I will go off and file it with Apple ).
attempting to fetch kAudioSessionProperty_AudioRoute is returning error code kAudioSessionUnsupportedPropertyError on any version of the simulator prior to 4.3 ( which is the latest version at time of writing ).
this one is dead easy to reproduce.
Start a new project ( I am using Xcode 4.0.2 Build 4A2002a, that is the standard build ), window-based project "AudioSessionBug"
include AudioToolbox framework
replace the application delegate's .m file with the following:
//
// 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];
[su开发者_Python百科per dealloc];
}
@end
check that it works.
now change deployment target to anything prior to 4.3. say 4.2.
run it again on iPad simulator 4.3 -- OK
run it again on iPad simulator 4.2 -- FAILI just received the following confirmation from Apple:
This was a bug that was fixed in 4.3 and we currently have no plans to fix bugs in earlier builds of the simulator.
精彩评论