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") 
     } 
    }) 
} 

enter image description here

为什么我得到有error: nil错误?

+0

因为斯威夫特2没有'错误: '再来一次。在尝试使用之前,你应该阅读关于Swift 2的知识;事情真的改变了很多! – matt

+0

你甚至可能想要(喘气!)读我的书! http://www.apeth.com/swiftBook/ch05.html#_throwing_and_catching_errors – matt

像这样:

try! session.setCategory(AVAudioSessionCategoryPlayAndRecord) 

让我们来看看,如果你能弄清楚自己,从模型,如何解决下一行...