iOS:这是音频会话模拟器错误吗?关键字: kAudioSessionProperty_AudioRoute kAudioSessionUnsupportedPropertyError
有人可以确认这是否确实是一个错误吗? (如果是这样,我会向苹果公司提交)。
在 4.3 之前的任何版本的模拟器上(这是撰写本文时的最新版本),尝试获取 kAudioSessionProperty_AudioRoute 都会返回错误代码 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 上再次运行 -- 失败
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];
[super 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 -- FAIL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚收到 Apple 的以下确认信息:
I just received the following confirmation from Apple: