iOSアプリをAppleSilicon環境(MacOS)で実行した時の判定
以下質問にて@nukka123さんに回答いただきました。
https://qiita.com/Howasuto/questions/3fc5ba81ea6240470ac4
以下のコードでAppleSilicon環境での実行時の判定を可能にします。
またUIDevice.current.userInterfaceIdiomでの判定基準はあくまでユーザーインターフェースのため、AppleSilicon環境で実行した際にはiPad用のインターフェースが適応されるため、判定結果としてはiPadとして判定されます。
if ProcessInfo.processInfo.isiOSAppOnMac {
// iOSアプリをMacで実行時
print("iOSAppOnMac")
} else if UIDevice.current.userInterfaceIdiom == .phone {
// iPhone用インターフェースで実行時
print("iPhone")
} else if UIDevice.current.userInterfaceIdiom == .pad {
// iPad用インターフェースで実行時
print("iPad")
} else if UIDevice.current.userInterfaceIdiom == .mac {
// Mac用インターフェースで実行時
print("Mac")
}
参考
https://developer.apple.com/documentation/foundation/processinfo/3608556-isiosapponmac
https://developer.apple.com/documentation/uikit/mac_catalyst/choosing_a_user_interface_idiom_for_your_mac_app/