Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;尝试一个AudioSession.sharedInstance().setCategory";仅在设备上返回零_Ios_Iphone_Swift - Fatal编程技术网

&引用;尝试一个AudioSession.sharedInstance().setCategory";仅在设备上返回零

&引用;尝试一个AudioSession.sharedInstance().setCategory";仅在设备上返回零,ios,iphone,swift,Ios,Iphone,Swift,返回错误: 域=NSOSStatusErrorDomain代码=-50“(空)” 对于任何在未来发现这一点的人来说,这里就是解决之道。只有将AVAudioSessionCategoryPlayback更改为AvaudioSessionCategoryPlayRecord时,它才能在设备上工作,如下所示: try AVAudioSession.sharedInstance() .setCategory(AVAudioSessionCategoryPlayback

返回错误:

域=NSOSStatusErrorDomain代码=-50“(空)”


对于任何在未来发现这一点的人来说,这里就是解决之道。只有将
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))))