检查UI_USER_INTERFACE_IDIOM()以确定它是iPhone还是iPad是否安全? [英] Is it safe to check for UI_USER_INTERFACE_IDIOM() to determine if it's an iPhone or iPad?

查看:178
本文介绍了检查UI_USER_INTERFACE_IDIOM()以确定它是iPhone还是iPad是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了这段代码,此处

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        str = [NSString stringWithString:@"Running as an iPad application"];
    } else {
        str = [NSString stringWithString:
                  @"Running as an iPhone/iPod touch application"];
    }

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Platform"
                                                    message:str
                                                   delegate:nil
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];   

此检查的安全性如何? Apple真的建议这样做吗?或者它可能会发生它不会将iPad检测为iPad或iPhone作为iPhone?

How safe is this check? Does Apple actually recommend doing this? Or can it happen that it won't detect an iPad as iPad, or iPhone as iPhone?

推荐答案

它应该足够安全,它很好 - 由Apple记录

It should be safe enough, it's well-documented by Apple.

这只是以下代码的简写:

That is just shorthand for the following code:

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// etc

如果你试图在低于iOS 3.2的任何东西上运行它,可能会失败(因为它只在那时引入),但这对你来说可能不是问题。

It could conceivably fail if you tried to run this on anything less than iOS 3.2 (as it was only introduced then), but this might not be an issue for you.

这篇关于检查UI_USER_INTERFACE_IDIOM()以确定它是iPhone还是iPad是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆