diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 70693e4a8..3ab3e1e34 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -1,5 +1,6 @@ import UIKit import Flutter +import AVFoundation @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { @@ -8,6 +9,18 @@ import Flutter didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) + + // 配置音频会话 + do { + if #available(iOS 10.0, *) { + try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) + try AVAudioSession.sharedInstance().setActive(true) + } + } catch { + print("Error setting up audio session: \(error)") + } + return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } +