ios - Swift 2 AVAudioSession setCategory 额外参数 'error'
<p><p>当我设置录制音频时,出现错误。</p>
<pre><code>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")
}
})
}
</code></pre>
<p> <a href="/image/QXvhA.png" rel="noreferrer noopener nofollow"><img src="/image/QXvhA.png" alt="enter image description here"/></a> </p>
<p>为什么我会因为有 <code>error: nil</code> 而收到错误消息?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>像这样:</p>
<pre><code>try! session.setCategory(AVAudioSessionCategoryPlayAndRecord)
</code></pre>
<p>让我们看看您是否可以从该模型中自己弄清楚如何修复下一行...</p></p>
<p style="font-size: 20px;">关于ios - Swift 2 AVAudioSession setCategory 额外参数'error',我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32878965/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32878965/
</a>
</p>
页:
[1]