本文介绍了检测设备类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序(用Objective-C编写)中,如何检测设备是iPhone,iPad还是iPhone5?
In my application (written in Objective-C), how do I detect if the device is an iPhone, iPad, or iPhone5 ?
if([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// [iphone] or [itouch]
} else {
// [ipad]
}
推荐答案
你可以轻松检测iphone,iphone5和iPad以下条件(但不是iTouch!iTouch被视为具有此代码的iPhone!): -
you can easly detect iphone, iphone5 and iPad with below condition (But not iTouch! iTouch is treated as if it were an iPhone with this code!):-
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
}
else
{
//iphone 3.5 inch screen
}
}
else
{
//[ipad]
}
更新
您还可以使用MACRO或定义变量来检查iPhone5,iPhon像贝娄那样的e4或iPad: -
You can also use MACRO or define Variable for check is that iPhone5,iPhone4 or iPad like Bellow:-
#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE
#define isiPhone (UI_USER_INTERFACE_IDIOM() == 0)?TRUE:FALSE
示例: -
if(isiPhone)
{
if (isiPhone5)
{
}
else
{
//iphone 3.5 inch screen
}
}
else
{
//[ipad]
}
这篇关于检测设备类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!