ios - “try 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))))
返回错误:
域=NSOSStatusErrorDomain 代码=-50 "(null)"
解决方案
对于将来发现此问题的任何人来说,这就是解决方案。如果您更改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))))
推荐阅读
- ios - 关闭 ios 应用程序时如何使用钥匙串?
- python - 比较数据框中两列的值时,如何修复TypeError“&:'str'和'bool'不支持的操作数类型”
- c# - Json.NET - 序列化对象但不完全序列化属性
- javascript - 如何将枚举值导出为单独的命名导出?
- slack-api - 如何让 slack api block kit 占据整个 slack 窗口的宽度?
- c# - 如何获取客户端远程IP地址
- javascript - 如何将数据传递给组件模板
- postgresql - LEFT JOIN 不能很好地与 Postgres 中的分区表配合使用?
- python - 为什么熊猫在写入 csv 时会删除前导零?
- python - 如何解决:for 循环方程的结果数组出现问题