33 lines
1.3 KiB
Swift
33 lines
1.3 KiB
Swift
import AVFoundation
|
|
import HaishinKit
|
|
import Logboard
|
|
import UIKit
|
|
|
|
let logger = LBLogger.with("com.haishinkit.Exsample.iOS")
|
|
|
|
@UIApplicationMain
|
|
final class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
var window: UIWindow?
|
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
|
// Logboard.with(HaishinKitIdentifier).level = .trace
|
|
let session = AVAudioSession.sharedInstance()
|
|
do {
|
|
// https://stackoverflow.com/questions/51010390/avaudiosession-setcategory-swift-4-2-ios-12-play-sound-on-silent
|
|
if #available(iOS 10.0, *) {
|
|
try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.defaultToSpeaker, .allowBluetooth])
|
|
} else {
|
|
session.perform(NSSelectorFromString("setCategory:withOptions:error:"), with: AVAudioSession.Category.playAndRecord, with: [
|
|
AVAudioSession.CategoryOptions.allowBluetooth,
|
|
AVAudioSession.CategoryOptions.defaultToSpeaker
|
|
])
|
|
try session.setMode(.voiceChat)
|
|
}
|
|
try session.setActive(true)
|
|
} catch {
|
|
logger.error(error)
|
|
}
|
|
return true
|
|
}
|
|
}
|