Swift 2 AVAudioSession setCategory额外参数'错误'
问题描述:
当我设置录制音频时,出现错误。Swift 2 AVAudioSession setCategory额外参数'错误'
if (session.respondsToSelector("requestRecordPermission:")) {
AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in
if granted {
print("granted")
session.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
session.setActive(true, error: nil)
self.recorder()
} else{
print("not granted")
}
})
}
为什么我得到有error: nil
错误?
答
像这样:
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord)
让我们来看看,如果你能弄清楚自己,从模型,如何解决下一行...
因为斯威夫特2没有'错误: '再来一次。在尝试使用之前,你应该阅读关于Swift 2的知识;事情真的改变了很多! – matt
你甚至可能想要(喘气!)读我的书! http://www.apeth.com/swiftBook/ch05.html#_throwing_and_catching_errors – matt