about summary refs log tree commit diff
path: root/modules/expo-bluesky-swiss-army/ios/PlatformInfo/ExpoPlatformInfoModule.swift
blob: cae4b983d100de1e125a6587eb8774d6f0868767 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import ExpoModulesCore

public class ExpoPlatformInfoModule: Module {
  public func definition() -> ModuleDefinition {
    Name("ExpoPlatformInfo")

    Function("getIsReducedMotionEnabled") {
      return UIAccessibility.isReduceMotionEnabled
    }

    Function("setAudioCategory") { (audioCategoryString: String) in
      let audioCategory = AVAudioSession.Category(rawValue: audioCategoryString)

      DispatchQueue.global(qos: .background).async {
        try? AVAudioSession.sharedInstance().setCategory(audioCategory)
      }
    }

    Function("setAudioActive") { (active: Bool) in
      if active {
        DispatchQueue.global(qos: .background).async {
          try? AVAudioSession.sharedInstance().setActive(true)
        }
      } else {
        DispatchQueue.global(qos: .background).async {
          try? AVAudioSession
            .sharedInstance()
            .setActive(
              false,
              options: [.notifyOthersOnDeactivation]
            )
        }
      }
    }
  }
}