如何检测我的 iPhone 应用程序是否正在 iPad 上运行
我有一个 opengl 应用程序,它在 RetinaDisplay 模式(双比例因子)下渲染得更好,并且我注意到 iPad 模拟具有低分辨率屏幕(正常比例因子)的 iPhone 应用程序。
当我的 iPhone 应用程序在 iPad 上运行时,我希望将比例因子加倍,以便从 Retina Display 图形中受益。但看起来iPad确实很好地假冒为iPhone(如果它是Retina显示屏就完美了......)
当我强制双倍缩放时,它工作得很好(至少在模拟器中,我没有iPad 进行测试)。
因此,我需要一种方法来知道我是否在 iPad 上运行,尽管很多情况告诉我它是一台旧 iPhone。
或者也许我不应该尝试这样做?
I have an opengl application that renders better in RetinaDisplay mode (double scale factor) and I noticed the iPad emulates an iPhone app with a low resolution screen (normal scale factor).
I want to double the scale factor when my iPhone app is run on an iPad, in order to benefit from Retina Display graphics. But it seems the iPad really well fakes being an iPhone (which would be perfect if only it was a Retina Display one...)
When I force the double scale, it works very well (at least in simulator, I do not have an iPad to test).
So I need a way to know if I am run on an iPad despite many things telling me it to be an old iPhone.
Or maybe I should not try to do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果应用程序是在 iPad 上以模拟器模式运行的 iPhone 应用程序,则它将具有 Phone 的 userInterfaceIdiom,但具有 iPad 的型号类型。您可以使用以下代码检查这一点:
If the app is an iPhone app running in the emulator mode on an iPad, it will have a userInterfaceIdiom of Phone, but a model type of iPad. You can check this with the following code:
如果您只想为 iPad 制作自定义代码(最有可能是自定义 UI 相关方法),那么您可以使用(按照 Apple 的指示)iOS 3.2 及更高版本中存在的 UI_USER_INTERFACE_IDIOM() 方法。
您可以在此处阅读更多信息 http://developer.apple.com/library/ios/#documentation/iphone/ Conceptual/iphoneosprogrammingguide/BuildTimeConfiguration/BuildTimeConfiguration.html
这是Apple推荐的方法
If you are looking to make custom code (most likely custom UI related methods) for the iPad only then you can use (as Apple directs) the UI_USER_INTERFACE_IDIOM() method that exists in iOS 3.2 and later
You can read more here http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BuildTimeConfiguration/BuildTimeConfiguration.html
This is the Apple recommended method
在文档中查找 UIDevice:
例如:
NSString *system = [[UIDevice currentDevice] 系统名称];
然后使用 [system isEqualToString:@"iPad"] 无论它是否是 ipad。
UIDevice 是一个非常好的类,它还有诸如 multiTaskingSupported、systemVersion 等内容。一定喜欢 UIKit ;)
Look up in the documentation, UIDevice:
For instance something like:
NSString *system = [[UIDevice currentDevice] systemName];
Then by using [system isEqualToString:@"iPad"] whether its an ipad or not.
UIDevice is a very nice class, it also has stuff like multiTaskingSupported, systemVersion etc. gotta love UIKit ;)
我认为是这样的:
if TARGET_IPHONE_SIMULATOR
NSString *hello = @"Hello, iOS Simulator!";
else
NSString *hello = @"你好,iOS 设备!";
endif
链接 苹果文档
i think it is that:
if TARGET_IPHONE_SIMULATOR
NSString *hello = @"Hello, iOS Simulator!";
else
NSString *hello = @"Hello, iOS device!";
endif
the link apple doc
关于
事实上,它在编译时说明了您正在编译的平台的目标,因此在运行之前您知道并执行必要的操作来处理特定的事情。
例如,我有不同的 URL 用于开发(在模拟器上运行)和生产使用,所以我做了一些类似的事情
about
In fact it says at compile time the target of the platform you are compiling for, thus before run you know and do the necessary for take care of something specific.
For example I have diferent URL for developing (running on simulator) and for production usage, so I do some like
你不应该能够分辨出区别,如果它是一个 iPhone 应用程序,那么据它所知它是在 iPhone 上运行的。如果您想针对 iPad,那么您需要为 iPad 目标构建它。
you shouldn't be able to tell the difference, if its an iPhone app, then as far as it can tell it is running on an iPhone. if you want to target an iPad, then you need to build it for an iPad target.