iphone - 检查 UI_USER_INTERFACE_IDIOM() 以确定它是 iPhone 还是 iPad 是否安全?

标签 iphone ipad universal-binary

我找到了这段代码,here :

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];   

这张支票的安全性如何?苹果真的建议这样做吗?或者它不会将 iPad 检测为 iPad,或将 iPhone 检测为 iPhone?

最佳答案

应该足够安全了,很好- documented由苹果公司提供。

这只是以下代码的简写:

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

如果您尝试在低于 iOS 3.2 的任何设备上运行此程序(因为当时才推出),它可能会失败,但这对您来说可能不是问题。

关于iphone - 检查 UI_USER_INTERFACE_IDIOM() 以确定它是 iPhone 还是 iPad 是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3905603/

相关文章:

iphone - 通用应用程序中的 Icon.png 文件错误

iphone - 除了 Firefox 扩展之外,Mac 上还有其他好的 SQLite 图形管理工具吗?

ios - 音频队列 : AudioQueueStart returns -50

javascript - 从 TCP 流中解析出数据段

ios - 将两个 iOS 项目合并为一个以进行通用构建

iphone - 为 iPad 启用 UIiStatusBar,在 Universal iOS 应用中为 iPhone 禁用

iphone - 除非调用复制,否则键盘不会显示在 UIWebView 内的输入字段上

iphone - 将 NSData 复制到 int32_t 变量中

ios - iTunes 连接本地化

iphone - 如何在多人游戏中同步数据(game-center ios)