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)”
答案 0 :(得分:2)
对于以后发现此问题的任何人来说,这都是解决方案。仅当您将AVAudioSessionCategoryPlayback
更改为AVAudioSessionCategoryPlayAndRecord
时,它才能在设备上运行:
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))))