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))))
Run Code Online (Sandbox Code Playgroud)
返回错误:
域=NSOSStatusErrorDomain 代码=-50“(空)”
对于将来发现此问题的任何人来说,这里就是解决方案。如果您更改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))))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1642 次 |
| 最近记录: |