简体   繁体   English

检测应用程序是否在iPad模拟器中运行

[英]Detect if app is running in iPad simulator

I can detect that app is running under iOS Simulator (using sysctlbyname("hw.machine") ), but how do I know if it is iPad of iPhone simulator? 我可以检测到该应用程序正在iOS模拟器下运行(使用sysctlbyname("hw.machine") ),但是如何知道它是否为iPhone模拟器的iPad?

Of course I may check [UIScreen mainScreen].bounds , but probably there are more elegant way? 当然,我可以检查[UIScreen mainScreen].bounds ,但是可能还有更优雅的方法?

iPhone: 苹果手机:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { }

iPad: iPad的:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { }

糟糕,刚刚发现[[UIDevice currentDevice] model]了我的需求。

you can look your current device model, like this: 您可以查看当前的设备型号,如下所示:

[[UIDevice CurrentDevice] model];

Also, you should take a look at this I think it will work for you. 另外,您应该看看这个,我认为它将为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM