[英]Is there a way to detect which platform is running in an Xcode iOS/MacOS Multiplatform app?
I'm working on an app with Xcode 14.0 beta 3 (14A5270f).我正在使用 Xcode 14.0 beta 3 (14A5270f) 开发一个应用程序。 The target Supported Destinations are:
支持的目标是:
iOS Deployment Target is 16.0 macOS Deployment Target is 13.0 iOS 部署目标是 16.0 macOS 部署目标是 13.0
I'm looking for some way to detect which destination is running.我正在寻找某种方法来检测正在运行的目的地。 I have a barcode scanning view that I only want to show on the iPhone or iPad destinations.
我有一个条码扫描视图,我只想在 iPhone 或 iPad 目的地上显示。
Thanks to https://stackoverflow.com/users/341994/matt for the documentation pointer in the comments that got me going.感谢https://stackoverflow.com/users/341994/matt在让我前进的评论中提供的文档指针。 Here's my final solution.
这是我的最终解决方案。
enum PlatformDestination: Int {
case iPhone
case iPad
case iOSOnMac
case MacCatalyst
case Mac
static func destination() -> PlatformDestination {
#if os(iOS)
switch UIDevice.current.userInterfaceIdiom {
case .phone:
return .iPhone
case .pad:
return .iPad
case .carPlay:
return .CarPlay
case .tv:
return .tvOS
case .unspecified:
break
case .mac:
return .iOSOnMac
default:
break
}
#endif
if ProcessInfo().isMacCatalystApp {
return .MacCatalyst
} else {
return .Mac
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.