OGeek|极客世界-中国程序员成长平台

标题: ios - Swift 2 AVAudioSession setCategory 额外参数 'error' [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:43
标题: ios - Swift 2 AVAudioSession setCategory 额外参数 'error'

当我设置录制音频时,出现错误。

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 而收到错误消息?



Best Answer-推荐答案


像这样:

try! session.setCategory(AVAudioSessionCategoryPlayAndRecord)

让我们看看您是否可以从该模型中自己弄清楚如何修复下一行...

关于ios - Swift 2 AVAudioSession setCategory 额外参数 'error',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32878965/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4