diff --git a/Sources/DeviceInformation/DeviceInfo.swift b/Sources/DeviceInformation/DeviceInfo.swift index 38d277d..9092148 100644 --- a/Sources/DeviceInformation/DeviceInfo.swift +++ b/Sources/DeviceInformation/DeviceInfo.swift @@ -22,7 +22,22 @@ public struct DeviceInfo: Sendable, Equatable, Identifiable { #if canImport(WatchKit) // os(watchOS) return WKInterfaceDevice.current().systemName #elseif canImport(UIKit) && !targetEnvironment(macCatalyst) // os(iOS) os(tvOS) os(visionOS) - return UIDevice.current.systemName + @MainActor + func _access() -> String { UIDevice.current.systemName } + func _assumeIsolated(_ work: @MainActor () -> T) -> T { + if #available(iOS 13, tvOS 13, *) { + return MainActor.assumeIsolated(work) + } else { + return withoutActuallyEscaping(work) { + unsafeBitCast($0, to: (() -> T).self)() + } + } + } + if Thread.isMainThread { + return _assumeIsolated(_access) + } else { + return DispatchQueue.main.sync { _assumeIsolated(_access) } + } #elseif os(macOS) || targetEnvironment(macCatalyst) return "macOS" #elseif os(Linux)