3

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 ?

4

6 回答 6

21

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
}
于 2013-02-13T22:24:44.767 回答
20

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

于 2010-12-16T23:39:02.873 回答
1

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

于 2010-12-16T22:14:57.363 回答
0

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

于 2010-12-16T22:16:13.337 回答
0

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
于 2011-01-06T17:05:20.743 回答
-4

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.

于 2010-12-16T22:15:21.723 回答