Skip to content

Commit

Permalink
Wrap CoreMediaIO inside macCatalyst condition (#2452)
Browse files Browse the repository at this point in the history
Apparently `#if canImport(CoreMediaIO)` is now true even if you are
trying to run the App on iOS instead of macOS, so this PR wraps it also
under `#if targetEnvironment(macCatalyst)`
  • Loading branch information
bgoncal authored Nov 16, 2023
1 parent 1df0738 commit e8598d9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class HACoreBlahObject {
}
}

#if targetEnvironment(macCatalyst)
#if canImport(CoreMediaIO)
import CoreMediaIO

Expand All @@ -74,7 +75,6 @@ class HACoreMediaObject: HACoreBlahObject {
}
#endif

#if targetEnvironment(macCatalyst)
import CoreAudio

class HACoreAudioObject: HACoreBlahObject {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Foundation

#if targetEnvironment(macCatalyst)
#if canImport(CoreMediaIO)
import CoreMediaIO
#endif
#if targetEnvironment(macCatalyst)
import CoreAudio
#endif

Expand All @@ -14,6 +14,7 @@ public protocol HACoreBlahProperty {
func getPropertyData(objectID: UInt32, dataSize: UInt32, output: UnsafeMutableRawPointer) -> OSStatus
}

#if targetEnvironment(macCatalyst)
#if canImport(CoreMediaIO)
public struct HACoreMediaProperty<Type>: HACoreBlahProperty {
public typealias ValueType = Type
Expand Down Expand Up @@ -49,7 +50,6 @@ public struct HACoreMediaProperty<Type>: HACoreBlahProperty {
}
#endif

#if targetEnvironment(macCatalyst)
public struct HACoreAudioProperty<Type>: HACoreBlahProperty {
public typealias ValueType = Type
public let address: AudioObjectPropertyAddress
Expand Down Expand Up @@ -82,7 +82,6 @@ public struct HACoreAudioProperty<Type>: HACoreBlahProperty {
}
}
}
#endif

#if canImport(CoreMediaIO)
extension HACoreMediaProperty {
Expand Down Expand Up @@ -151,7 +150,6 @@ extension HACoreMediaProperty {
}
#endif

#if targetEnvironment(macCatalyst)
extension HACoreAudioProperty {
static var deviceUID: HACoreAudioProperty<Unmanaged<CFString>> {
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

#if canImport(CoreMediaIO)
#if canImport(CoreMediaIO) && targetEnvironment(macCatalyst)
import CoreMediaIO

class HACoreMediaObjectCamera: HACoreMediaObject {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

#if canImport(CoreMediaIO)
#if canImport(CoreMediaIO) && targetEnvironment(macCatalyst)
import CoreMediaIO

class HACoreMediaObjectSystem: HACoreMediaObject {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Shared/API/Webhook/Sensors/InputOutputDeviceSensor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ private class InputOutputDeviceUpdateSignaler: SensorProviderUpdateSignaler {

#if targetEnvironment(macCatalyst)
case coreAudio(AudioObjectID)
#endif
#if canImport(CoreMediaIO)
case coreMedia(CMIOObjectID)
#endif
#endif

var id: UInt32 {
switch self {
case .invalid: return .max
#if targetEnvironment(macCatalyst)
case let .coreAudio(id): return id
#endif
#if canImport(CoreMediaIO)
case let .coreMedia(id): return id
#endif
#endif
}
}
}
Expand All @@ -40,11 +40,11 @@ private class InputOutputDeviceUpdateSignaler: SensorProviderUpdateSignaler {
required init(signal: @escaping () -> Void) {
self.signal = signal

#if targetEnvironment(macCatalyst)
#if canImport(CoreMediaIO)
addCoreMediaObserver(for: CMIOObjectID(kCMIOObjectSystemObject), property: .allDevices)
#endif

#if targetEnvironment(macCatalyst)
addCoreAudioObserver(for: AudioObjectID(kAudioObjectSystemObject), property: .allDevices)
#endif
}
Expand All @@ -70,7 +70,6 @@ private class InputOutputDeviceUpdateSignaler: SensorProviderUpdateSignaler {
) {
addObserver(object: .coreAudio(id), property: property)
}
#endif

#if canImport(CoreMediaIO)
func addCoreMediaObserver<PropertyType>(
Expand All @@ -80,6 +79,7 @@ private class InputOutputDeviceUpdateSignaler: SensorProviderUpdateSignaler {
addObserver(object: .coreMedia(id), property: property)
}
#endif
#endif
}

public class InputOutputDeviceSensor: SensorProvider {
Expand All @@ -89,19 +89,19 @@ public class InputOutputDeviceSensor: SensorProvider {

public let request: SensorProviderRequest

#if targetEnvironment(macCatalyst)
#if canImport(CoreMediaIO)
let cameraSystemObject: HACoreMediaObjectSystem
#endif
#if targetEnvironment(macCatalyst)
let audioSystemObject: HACoreAudioObjectSystem
#endif

public required init(request: SensorProviderRequest) {
self.request = request
#if targetEnvironment(macCatalyst)
#if canImport(CoreMediaIO)
self.cameraSystemObject = HACoreMediaObjectSystem()
#endif
#if targetEnvironment(macCatalyst)
self.audioSystemObject = HACoreAudioObjectSystem()
#endif
}
Expand Down

0 comments on commit e8598d9

Please sign in to comment.