Reputation: 1075
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))))
Returns the error:
Domain=NSOSStatusErrorDomain Code=-50 "(null)"
Upvotes: 5
Views: 2262
Reputation: 1075
For anyone who finds this in the future here is the solve. It only works on device if you change AVAudioSessionCategoryPlayback
to AVAudioSessionCategoryPlayAndRecord
like this:
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))))
Upvotes: 8