“尝试AVAudioSession.sharedInstance().setCategory";仅在设备上返回nil [英] "try AVAudioSession.sharedInstance().setCategory" returns nil on only device

查看:107
本文介绍了“尝试AVAudioSession.sharedInstance().setCategory";仅在设备上返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

try AVAudioSession.sharedInstance()
                  .setCategory(AVAudioSessionCategoryPlayback,
                               with: AVAudioSessionCategoryOptions(rawValue: UInt(UInt8(AVAudioSessionCategoryOptions.defaultToSpeaker.rawValue)
                                                                                | UInt8(AVAudioSessionCategoryOptions.allowAirPlay.rawValue)
                                                                                | UInt8(AVAudioSessionCategoryOptions.allowBluetooth.rawValue)
                                                                                | UInt8(AVAudioSessionCategoryOptions.allowBluetoothA2DP.rawValue))))

返回错误:

Domain = NSOSStatusErrorDomain Code = -50(null)"

Domain=NSOSStatusErrorDomain Code=-50 "(null)"

推荐答案

对于以后发现此问题的任何人来说,这都是解决之道.仅当将AVAudioSessionCategoryPlayback更改为AVAudioSessionCategoryPlayAndRecord时,它才能在设备上运行:

For anyone who finds this in the future here is the solve. It only works on device if you change AVAudioSessionCategoryPlayback to AVAudioSessionCategoryPlayAndRecord like this:

try AVAudioSession.sharedInstance()
                  .setCategory(AVAudioSessionCategoryPlayAndRecord,
                               with: AVAudioSessionCategoryOptions(rawValue: UInt(UInt8(AVAudioSessionCategoryOptions.defaultToSpeaker.rawValue)
                                                                                | UInt8(AVAudioSessionCategoryOptions.allowAirPlay.rawValue)
                                                                                | UInt8(AVAudioSessionCategoryOptions.allowBluetooth.rawValue)
                                                                                | UInt8(AVAudioSessionCategoryOptions.allowBluetoothA2DP.rawValue))))

这篇关于“尝试AVAudioSession.sharedInstance().setCategory";仅在设备上返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆