4

我在这里找到了这段代码:

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?

4

1 回答 1

7

它应该足够安全,Apple 有据可查

这只是以下代码的简写:

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

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

于 2010-10-11T11:13:33.620 回答