まいまいワークス

主にiPhoneアプリの開発で考えた事、調べた事、感じた事などを記していきます。

iPhoneとiPadの判別

端末の判別に[[UIDevice currentDevice].modelを使用する事がありますが、このやり方だとiPhone, iPad, iPodTouch, iPhone Simulator, iPad Simulatorの値が返ってくるため、単純にユニバーサルアプリ等でiPhone, ipadの判別をしたい場合は処理が煩雑になったりします。

ここは素直にUniversalアプリのテンプレに従って

iPhone

[[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone

iPad

[[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad

で判別し、例えば

#define is_iPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ? YES:NO)

このようなマクロを設定しておくのが良さそう。

使用例

#define is_iPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ? YES:NO)

NSLog(@"iPad=%d",is_iPad);

//iPhone
iPad=0

//iPad
iPad=1