本文介绍了AVAudioEngine.connect在硬件而非模拟器上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var engine:AVAudioEngine!
var format = engine.inputNode.inputFormat(forBus: 0)
engine.connect(engine.inputNode, to: engine.mainMixerNode, format: format)
在AVAudioEngine.connect函数中,我的应用仅在硬件上崩溃但是在模拟器中就可以了.
in function AVAudioEngine.connect make my app crash only on hardwarebut in simulator it's fine.
当我在硬件上运行时,提示错误.
When I run on hardware it's error says.
Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
terminating with uncaught exception of type NSException
推荐答案
我知道了.我只是将AVAudioSession类别类型设置为错误.如果您遇到相同的错误,请查看AVAudioSession并确保您的AVAudioSession类别处于正确的麦克风权限设置中.例如
I figure it out.I just set the AVAudioSession category type wrong.If you have the same error take a look at AVAudioSession and make sure that your AVAudioSession category is in the right setting for microphone permission.for instance
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: .mixWithOthers)
使用此设置将允许应用同时使用麦克风和播放声音.
with this setting will allow app to use microphone and play sound in the same time.
这篇关于AVAudioEngine.connect在硬件而非模拟器上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!