相关疑难解决方法(0)

以编程方式检测iPad/iPhone硬件的最佳方式

我需要找到的原因是,在iPad上,UIPickerView在横向方向上具有与在纵向方向相同的高度.在iPhone上它是不同的.iPad编程指南为UIDevice引入了一个"成语"值:

    UIDevice* thisDevice = [UIDevice currentDevice];
    if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        // iPad
    }
    else
    {
        // iPhone
    }
Run Code Online (Sandbox Code Playgroud)

你在iPad(3.2)但不是iPhone(3.1.3)时工作正常 - 所以看起来还需要有一个ifdef来有条件地编译那个支票,比如:

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30200
        UIDevice* thisDevice = [UIDevice currentDevice];
        if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
        {
            // etc.
        }
#endif
Run Code Online (Sandbox Code Playgroud)

对我而言,开始看起来非常笨拙.什么是更好的方式?

iphone orientation ipad

46
推荐指数
5
解决办法
6万
查看次数

检测设备型号(iPhone/iPod Touch)的正确方法?

这是检测用户正在运行的设备的正确方法吗?

NSString *currentModel = [[UIDevice currentDevice] model];
if ([currentModel isEqualToString:@"iPhone"]) {
    // The user is running on iPhone so allow Call, Camera, etc.
} else {
    // The user is running on a different device (iPod / iPad / iPhone Simulator) disallow Call.
}
Run Code Online (Sandbox Code Playgroud)

iphone model ipod-touch detection

2
推荐指数
1
解决办法
2338
查看次数

标签 统计

iphone ×2

detection ×1

ipad ×1

ipod-touch ×1

model ×1

orientation ×1