`
简单的茶
  • 浏览: 87702 次
  • 性别: Icon_minigender_2
  • 来自: 昆明
社区版块
存档分类
最新评论

kAudioSessionIncompatibleCategory

    博客分类:
  • iOS
 
阅读更多
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.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics