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
The above answer (by Rhythmic Fistman) is correct if your app is not compatible with iOS 9 or below.
If your app is compatible with iOS 9 you will see the next error:
'setCategory' is unavailable in Swift
In that case there is a bug with Swift 4.2, this is an issue with AVFoundation in Xcode 10's SDKs, you can work around it by writing an Objective-C function that calls through to the old API, since they're still available in Objective-C.
In the next link you can read more details:
https://forums.swift.org/t/using-methods-marked-unavailable-in-swift-4-2/14949