&引用;尝试一个AudioSession.sharedInstance().setCategory";仅在设备上返回零
返回错误: 域=NSOSStatusErrorDomain代码=-50“(空)”&引用;尝试一个AudioSession.sharedInstance().setCategory";仅在设备上返回零,ios,iphone,swift,Ios,Iphone,Swift,返回错误: 域=NSOSStatusErrorDomain代码=-50“(空)” 对于任何在未来发现这一点的人来说,这里就是解决之道。只有将AVAudioSessionCategoryPlayback更改为AvaudioSessionCategoryPlayRecord时,它才能在设备上工作,如下所示: try AVAudioSession.sharedInstance() .setCategory(AVAudioSessionCategoryPlayback
对于任何在未来发现这一点的人来说,这里就是解决之道。只有将
AVAudioSessionCategoryPlayback
更改为AvaudioSessionCategoryPlayRecord
时,它才能在设备上工作,如下所示:
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))))
仅供参考-用
[.defaultToSpeaker、.allowAirPlay、.allowBluetooth、.allowBluetoothA2DP]
用什么替换它?@rmaddy请阅读我的全部评论。它可能与您的问题无关,但这是在Swift中提供多个选项的正确方式。如果它与问题无关,则不要评论。您比我更了解您的所有声誉点@rmaddyYes,这是因为.allowAirPlay类别选项仅在类别播放和录制标签:Swift 5:尝试AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.PlayAndRecord,选项:AVAudioSession.Category选项(rawValue:UInt(UInt8)(AVAudioSession.CategoryOptions.defaultToSpeaker.rawValue)|UInt8(AVAudioSession.CategoryOptions.allowAirPlay.rawValue)| UInt8(AVAudioSession.CategoryOptions.allowBluetooth.rawValue)| UInt8(AVAudioSession.CategoryOptions.allowBluetoothA2DP.rawValue)))
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))))