To play sound even on Silent mode I use to use below method. But how it\'s not working.
// Works on Swift 3
do {
try AVAudioSession.sharedInstance().se
As a workaround, you can call the Objective-C AVAudioSession.setCategory:
method with the NSObject.performSelector:
:
if #available(iOS 10.0, *) {
try! AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback)
}
else {
// Workaround until https://forums.swift.org/t/using-methods-marked-unavailable-in-swift-4-2/14949 isn't fixed
AVAudioSession.sharedInstance().perform(NSSelectorFromString("setCategory:error:"), with: AVAudioSession.Category.playback)
}
If you want to set the category and options for iOS 9 and earlier then use:
AVAudioSession.sharedInstance().perform(NSSelectorFromString("setCategory:withOptions:error:"), with: AVAudioSession.Category.playback, with: [AVAudioSession.CategoryOptions.duckOthers])
Issue is fixed in Xcode 10.2.