AudioKit 在设备上崩溃,但在模拟器上不崩溃

AudioKit crashes on device, but not simulator

在下面的代码中,AudioKit.start() 在我的 iPhone SE 和 iOS 10.1.1 上崩溃。它在模拟器上运行良好。

private func play(note: Int) {
  let pluckedString = AKPluckedString()
  AudioKit.output = pluckedString
  AudioKit.start() // <-- Crash here!
  let frequency = note.midiNoteToFrequency()
  pluckedString.trigger(frequency: frequency)
}

控制台错误日志为

2016-12-04 10:51:45.765130 MyApp[1833:720319] [aurioc] 889: failed: -10851 (enable 2, outf< 2 ch,      0 Hz, Float32, non-inter> inf< 2 ch,      0 Hz, Float32, non-inter>)
2016-12-04 10:51:45.766519 MyApp[1833:720319] [aurioc] 889: failed: -10851 (enable 2, outf< 2 ch,  44100 Hz, Float32, non-inter> inf< 2 ch,      0 Hz, Float32, non-inter>)
2016-12-04 10:51:45.767008 MyApp[1833:720319] [aurioc] 889: failed: -10851 (enable 2, outf< 2 ch,  44100 Hz, Float32, non-inter> inf< 2 ch,      0 Hz, Float32, non-inter>)
2016-12-04 10:51:45.767982 MyApp[1833:720319] [central] 54:   ERROR:    [0x1b42d7c40] >avae> AVAudioEngineGraph.mm:2515: PerformCommand: error -10851

我错过了什么?与模拟器相比,我找不到任何关于设备所需额外设置的文档。 AudioKit的版本是3.5。 XCode 版本为 8.1

我发现了问题。我为音频会话设置了一个录音类别。通过确保音频会话类别在播放时不是 AVAudioSessionCategoryRecord;我的应用程序不再崩溃了。