簡體   English   中英

“嘗試AVAudioSession.sharedInstance()。setCategory”僅在設備上返回nil

[英]“try AVAudioSession.sharedInstance().setCategory” returns nil on only device

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)”

對於今后發現這一點的人來說,這就是解決方案。 它只適用於設備,如果您將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))))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM