2024-08-05 21:21:34 +02:00
|
|
|
import ExpoModulesCore
|
|
|
|
|
|
|
|
public class ExpoPlatformInfoModule: Module {
|
2024-08-14 21:21:14 +02:00
|
|
|
private var prevAudioActive: Bool?
|
|
|
|
private var prevAudioCategory: AVAudioSession.Category?
|
|
|
|
|
2024-08-05 21:21:34 +02:00
|
|
|
public func definition() -> ModuleDefinition {
|
|
|
|
Name("ExpoPlatformInfo")
|
|
|
|
|
|
|
|
Function("getIsReducedMotionEnabled") {
|
|
|
|
return UIAccessibility.isReduceMotionEnabled
|
|
|
|
}
|
2024-08-09 12:05:12 +02:00
|
|
|
|
2024-08-09 23:35:26 +02:00
|
|
|
Function("setAudioCategory") { (audioCategoryString: String) in
|
|
|
|
let audioCategory = AVAudioSession.Category(rawValue: audioCategoryString)
|
2024-08-14 21:21:14 +02:00
|
|
|
if audioCategory == self.prevAudioCategory {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
self.prevAudioCategory = audioCategory
|
2024-08-13 05:08:51 +02:00
|
|
|
DispatchQueue.global(qos: .background).async {
|
|
|
|
try? AVAudioSession.sharedInstance().setCategory(audioCategory)
|
|
|
|
}
|
2024-08-09 23:35:26 +02:00
|
|
|
}
|
|
|
|
|
2024-08-10 01:52:23 +02:00
|
|
|
Function("setAudioActive") { (active: Bool) in
|
2024-08-14 21:21:14 +02:00
|
|
|
if active == self.prevAudioActive {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
self.prevAudioActive = active
|
2024-08-10 01:52:23 +02:00
|
|
|
if active {
|
2024-08-13 05:08:51 +02:00
|
|
|
DispatchQueue.global(qos: .background).async {
|
|
|
|
try? AVAudioSession.sharedInstance().setActive(true)
|
|
|
|
}
|
2024-08-09 12:05:12 +02:00
|
|
|
} else {
|
2024-08-13 05:08:51 +02:00
|
|
|
DispatchQueue.global(qos: .background).async {
|
|
|
|
try? AVAudioSession
|
|
|
|
.sharedInstance()
|
|
|
|
.setActive(
|
|
|
|
false,
|
|
|
|
options: [.notifyOthersOnDeactivation]
|
|
|
|
)
|
|
|
|
}
|
2024-08-09 12:05:12 +02:00
|
|
|
}
|
|
|
|
}
|
2024-08-05 21:21:34 +02:00
|
|
|
}
|
|
|
|
}
|