在8.2
UserInterfaceIdiom()
是
#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)
在8.3
UserInterfaceIdiom()
是
static inline UIUserInterfaceIdiom UI_USER_INTERFACE_IDIOM() {
return ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ?
[[UIDevice currentDevice] userInterfaceIdiom] :
UIUserInterfaceIdiomPhone);
}
所以#ifdef UI_USER_INTERFACE_IDIOM
总是假的8.3
请注意,标题说
提供 UI_USER_INTERFACE_IDIOM() 函数以在部署到低于 3.2 的 iOS 版本时使用。如果您要为其部署的 iPhone/iOS 的最早版本是 3.2 或更高版本,您可以直接使用 -[UIDevice userInterfaceIdiom]。
所以建议你重构为
+ (BOOL) isiPad
{
static BOOL isIPad = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isIPad = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
});
return isIPad;
}