I actually think I figured it out. It seems I need to capture the category before I change it:
// Save previous category
self.previousCategory = audioSession.category
And then set it back before I stop the audio session being active:
do {
if let category = self.previousCategory {
try audioSession.setCategory(category)
}
try audioSession.setActive(false, options: .notifyOthersOnDeactivation)
} catch {
print(error)
}
I no longer get the error that an audio session/object is running.
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: