簡単だけど、いつも何だっけかなぁって思う各種判定。
コードスニペットに登録しても便利かも。
細かいデバイスの取得はErica SadunさんのUIDevice-Hardwareが便利です。
YSDeviceHelper.h
// iPhoneか
+ (BOOL)isPhone;
// Retinaディスプレイか
+ (BOOL)isRetina;
// 4inch(iPhone5)か
+ (BOOL)is568h;
// 言語環境が日本語か
+ (BOOL)isJapaneseLanguage;
YSDeviceHelper.m
+ (BOOL)isPhone
{
static BOOL isPhone;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isPhone = [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone;
});
return isPhone;
}
+ (BOOL)isRetina
{
static BOOL isRetina;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isRetina = [UIScreen mainScreen].scale == 2.f;
});
return isRetina;
}
+ (BOOL)is568h
{
static BOOL is568h;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
CGFloat height = [UIScreen mainScreen].bounds.size.height;
is568h = height == 568.f;
});
return is568h;
}
+ (BOOL)isJapaneseLanguage
{
static BOOL isJapanese;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSArray *languages = [NSLocale preferredLanguages];
NSString *currentLanguage = [languages objectAtIndex:0];
isJapanese = [currentLanguage isEqualToString:@"ja"];
});
return isJapanese;
}