문제

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 ?

도움이 되었습니까?

해결책

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.

다른 팁

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

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
}

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

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

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top