How to let audio play when the iOS device is in Silent mode ?

By default, audio only plays if the iOS device is unmuted (mute side switcher on iOS devices).

In order for audio to work by default, the app must declare that audio playback as a core feature of the app, and thus it should not be muted in “Silent Mode”.

This can be done by configuring the AVAudioSessionCategoryPlayback category: Apple Developer Documentation

You can choose from several audio session categories and settings to customize your app's audio behavior.

Bellow an example on how to modify the "AppDelegate.swift" file to change the default behavior:

import AVFoundation
import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate { 
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    var categoryError :NSError?
    var success: Bool
    do {
        // see https://developer.apple.com/documentation/avfoundation/avaudiosessioncategoryplayback
        // and https://developer.apple.com/documentation/avfoundation/avaudiosessionmodemovieplayback
        try AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback, options: .duckOthers)
        success = true
    } catch let error as NSError {
        categoryError = error
        success = false
    }
    if !success {
        print("AppDelegate Debug - Error setting AVAudioSession category.  Because of this, there may be no sound. \(categoryError!)")
    }
    // Override point for customization after application launch.
    return true
    }
  
    // MARK: UISceneSession Lifecycle
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
    // Called when a new scene session is being created.
    // Use this method to select a configuration to create the new scene with.
    return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }
  
    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
    // Called when the user discards a scene session.
    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }  
}