iOSアプリを開発するにあたって、iPhoneとiPadの判定が必要な状況が出てくると思います。そういうときは以下の方法を使って判別しましょう。
ユニバーサル化がされているアプリの場合
1 2 3 4 5 |
if UIDevice.current.userInterfaceIdiom == .pad { print("iPad") }else UIDevice.current.userInterfaceIdiom == . phone{ print("iPhone") } |
ユニバーサル化がされていないアプリの場合
1 2 3 4 5 |
if ( UIDevice.current.model.range(of: "iPad") != nil){ print("iPad") } else { print("iPhone") } |
通常の場合こちらの方法を使うと解決します。ユニバーサル化していないのに、上の方法を採用すると想定した動作をしないので注意が必要です。