检查 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];
此检查有多安全?苹果真的建议这样做吗?或者它不会将 iPad 检测为 iPad,或将 iPhone 检测为 iPhone?
I've found this code, 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];
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该足够安全,很好-由 Apple 记录。
这只是以下代码的简写:
如果您尝试在低于 iOS 3.2 的系统上运行此代码(因为当时才引入),它可能会失败,但这对您来说可能不是问题。
It should be safe enough, it's well-documented by Apple.
That is just shorthand for the following code:
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.