kAudioSessionIncompatibleCategory

A Note About kAudioSessionIncompatibleCategory Error on iOS 5 and 6

There is bug apparent on both iOS 5 and 6 (but not iOS 7) that manifests in apps that use the PlayAndRecord audio session category under certain multitasking conditions. The issue is triggered reliably via the following steps:

Open one app that uses both PlayAndRecord and background audio.
Open a second app that also uses PlayAndRecord and background audio.
Quit the first app, via the multitasking bar.
Open the first app again. The app will experience the error.
The error can also be caused by launching certain combinations of apps.

It results in a completely inoperable audio session, as well as a kAudioSessionIncompatibleCategory ('!cat') error when querying the kAudioSessionProperty_CurrentHardwareInputNumberChannels audio session property.

Once the error appears, the problem can only be resolved by quitting some or all running audio apps - unless the workaround described below is used.

See rdar://13022588 for further description.

We strongly recommend writing code to recognize this error state, and responds appropriately: First by implementing the workaround described below, and in the event of a failure in the workaround, informing the user accordingly, recommending that the user relaunches their apps.

Here's our proposed message to the user:

You’ve discovered a known issue with the iOS audio system that we have no control over.

Please relaunch all your music apps, making sure you launch the Audiobus app first.

You can frequently recover from this error by deactivating and reactivating the audio session:

AudioSessionSetActive(false);
AudioSessionSetActive(true);
This seems to resolve the issue when it arises sometimes, but at other times, it has no effect.

Nevertheless, we recommend making use of it to mitigate some of the effects of the bug, until Apple fix it.

The implementation of the workaround is simple: Early in your app's audio initialization, check the kAudioSessionProperty_CurrentHardwareInputNumberChannels property. If you get a kAudioSessionIncompatibleCategory error, restart the audio session:

UInt32 channels;
OSStatus result = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareInputNumberChannels, &size, &channels);
if ( result == kAudioSessionIncompatibleCategory ) {
// Audio session error (rdar://13022588). Power-cycle audio session.
AudioSessionSetActive(false);
AudioSessionSetActive(true);
result = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareInputNumberChannels, &size, &channels);
if ( result != noErr ) {
NSLog(@"Got error %d while querying input channels", result);
}
}


If there is no need for U to know the kAudioSessionProperty_CurrentHardwareInputNumberChannels value, you can delete the AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareInputNumberChannels, &size, &channels); to avoid the problem.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值