2
1

More than 1 year has passed since last update.

【iOS】AppleSilicon環境(MacOS)でiOSアプリを実行した時にMacで実行しているか判定する

Last updated at Posted at 2022-02-24

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/

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1