How to detect I'm using an iPad instead of an Iphone?

How to detect I'm using an iPad instead of an Iphone?
0.0 0


How can I detect inside the code that the user is using an iPad instead of an iPhone, to adjust the positions and loading the right assets?

I was following a book on cocos2d and trying to adapt the code to cocos2d-x, but I haven’t been able to find
a function called UI_USER_INTERFACE_IDIOM() which returns UIUserInterfaceIdiomPad when the user is using an iPad.

So far I’ve been thinking of checking the resolution using the director, but is there a cleaner way to do this?



I think 3 premises is required:
# iOS 3.2 and later SDK
# import “UIDevice.h”
# This marco uses objc syntax, so you need to rename your cpp file using this marco to .mm subfix



I also want to know how to do this detection. Could you give more detail about this ?

I have a DeviceSettings.h used in my original cocos2d project, and it works fine.

But when I include this DeviceSettings.h into current cocos2d-x ccp file, I got 999+ compile error.

Could you give me some light about this, thank you.



I think I found the solution, I just wrote this hope can give anyone who encounter the same problem as me.

The solution is just simple, if you want to migrate the object-c macro into your c*+ files.
You need to change the c*+ file type to “Objective-C*+ source” in “Identity and Type”, and vice versa.
I do this and my 999* errors just gone. It’s a big happy to see these annoying red symbols disappear.

BTW, I use the Xcode 4.

Hope this information can help someone. :slight_smile:


Hi… M not able to do understand what you did? I also wanna do the same stuff. Please explain a bit more.


Every file has a file type - .cpp is “C+ source" if you like to use Obj-C stuff you must make the file where you include Obj-C stuff to "Objective-C+” file like mentioned above.
Quick fix: rename your**.cpp file into *.mm


I have another way, and successfully used it in my game to scale content or do other stuff. But it’s kinda hacky, and very manual.
I check the current size (width or height) of the screen of device getting these information via normal CCDirector. You can see here


@Wasin : The thread is about detecting iPad with Cocos2d-x your code is about scaling coords


@Herman : The checking condition can be used to detect which device the application is currently running on. Anyway, it could be another way around.


@Wasin: Ok, thanks. Just be aware there is a retina iPad3 out soon.


Anyway I’m sorry not to post the direct to the point pure code.
So I cut it off and it’s below.

CCSize winSize = CCDirector::sharedDirector()->getWinSize();

// detect which device is currently running if(winSize.width == 480) _deviceActiveUse = DEVICE_IPODIPHONE_3; else if(winSize.width == 960) _deviceActiveUse = DEVICE_IPHONE_4; else if(winSize.width == 1024) _deviceActiveUse = DEVICE_IPAD;


@Herman : Thanks for reminding !


Sorry to dig up, but just to notify that I’ve tested including a condition checking for iPad 3 resolution but CCDirector::sharedDirector()->getWinSize().width still returns the same 1024.
I’m not sure whether this is not yet support or anything, I tested it via Simulator and set the device to iPad (Retina).

I created another thread at


both retina and non-retina will return the width as 1024 (as in ‘point’ but not pixel)


Ohh, so it means I would get it via getWinSizeInPixel(). I will try it out ASAP. Thanks!


Ohh, so it means I would get it via getWinSizeInPixel(). I will try it out ASAP. Thanks!


Follow Walzer’s instruction and use this code to detect both device kind & retina display:


// Determine device kind
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  // iPad
} else {
  // iPhone

// Determine retina display
if ([UIScreen instancesRespondToSelector:@selector(scale)] && UIScreen.mainScreen.scale > 1.0) {
  // Retina
} else {
  // Non-retina


Another solution which just uses the Cocos2d-x API

#define CC_IS_IPAD() (CCDirector::sharedDirector()->getWinSize().width==1024||CCDirector::sharedDirector()->getWinSize().height==1024) #define CC_IS_IPAD3() (CC_IS_IPAD() && CC_CONTENT_SCALE_FACTOR()>1.0f)


Thanks Wang Jabi, andHerman for suggestion.
I tested getWinSizeInPixels() and getting the scaling factor and do regular check with normal getWinSize(), it all works out. According to this, I found a fatal flaw in my code. Thanks for pointing me out !


Thanks @Zhi Eng Lee as well, your suggestion leads me to dig it up.
BTW: Sorry to dig this post up too far :wink: