如何检测我的 iPhone 应用程序是否正在 iPad 上运行

发布于 2024-10-07 16:14:36 字数 349 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

_蜘蛛 2024-10-14 16:14:36

如果应用程序是在 iPad 上以模拟器模式运行的 iPhone 应用程序,则它将具有 Phone 的 userInterfaceIdiom,但具有 iPad 的型号类型。您可以使用以下代码检查这一点:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
    [[[UIDevice currentDevice] model] hasPrefix:@"iPad"]) {
    // This app is an iPhone app running on an 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:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
    [[[UIDevice currentDevice] model] hasPrefix:@"iPad"]) {
    // This app is an iPhone app running on an iPad
}
夜光 2024-10-14 16:14:36

如果您只想为 iPad 制作自定义代码(最有可能是自定义 UI 相关方法),那么您可以使用(按照 Apple 的指示)iOS 3.2 及更高版本中存在的 UI_USER_INTERFACE_IDIOM() 方法。

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    // The device is an iPad running iPhone 3.2 or later.
}
else
{
    // The device is an iPhone or iPod touch.

}

您可以在此处阅读更多信息 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

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    // The device is an iPad running iPhone 3.2 or later.
}
else
{
    // The device is an iPhone or iPod touch.

}

You can read more here http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BuildTimeConfiguration/BuildTimeConfiguration.html

This is the Apple recommended method

歌枕肩 2024-10-14 16:14:36

在文档中查找 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 ;)

§普罗旺斯的薰衣草 2024-10-14 16:14:36

我认为是这样的:

// Set hello to "Hello, <device or simulator>"!

if TARGET_IPHONE_SIMULATOR

NSString *hello = @"Hello, iOS Simulator!";

else

NSString *hello = @"你好,iOS 设备!";

endif

链接 苹果文档

i think it is that:

// Set hello to "Hello, <device or simulator>"!

if TARGET_IPHONE_SIMULATOR

NSString *hello = @"Hello, iOS Simulator!";

else

NSString *hello = @"Hello, iOS device!";

endif

the link apple doc

梦断已成空 2024-10-14 16:14:36

关于

这实际上只会告诉你是否
该应用程序正在模拟中运行
环境或实际设备上,
并且不影响是否
平台是 iPad 或 iPhone。

事实上,它在编译时说明了您正在编译的平台的目标,因此在运行之前您知道并执行必要的操作来处理特定的事情。

例如,我有不同的 URL 用于开发(在模拟器上运行)和生产使用,所以我做了一些类似的事情

#if TARGET_IPHONE_SIMULATOR
#define URL @"http://192.x.x.x/request"
#else
#define URL @"http://example.com/request"
#endif

about

This actually will only tell you if
the app is being run in a simulated
environment, or on an actual device,
and has no influence on whether the
platform is iPad or iPhone.

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

#if TARGET_IPHONE_SIMULATOR
#define URL @"http://192.x.x.x/request"
#else
#define URL @"http://example.com/request"
#endif
浅唱々樱花落 2024-10-14 16:14:36

你不应该能够分辨出区别,如果它是一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文