[英]Custom UIWindow on iOS 8.3 iPad works on simulator but not device
[英]How can I detect if device is an iPad in iOS 8.3?
我們將SDK更新到iOS 8.3,突然之間,我們的iPad檢測方法無法正常工作:
+ (BOOL) isiPad
{
#ifdef UI_USER_INTERFACE_IDIOM
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
#endif
return NO;
}
永遠不會輸入ifdef
塊,所以return NO;
總是運行。 如何在不使用UI_USER_INTERFACE_IDIOM()
情況下檢測設備是否為iPad?
我正在使用:
在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
始終為false
請注意標題說
提供了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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.