How to detect my iPhone app is being run on an iPad

折月煮酒 提交于 2019-12-19 04:21:19

问题


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 ?


回答1:


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.




回答2:


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




回答3:


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
}



回答4:


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




回答5:


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




回答6:


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


来源:https://stackoverflow.com/questions/4465832/how-to-detect-my-iphone-app-is-being-run-on-an-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!