Reputation: 9590
I am currently working on a cocos2d game for iOS. Currently I am checking at runtime if it is an ipad or iphone running and adjusting coordinates et.c. for this.
But now I want two versions, one for iPad and one for iPod touch/iPhone. So I want two targets but still use the same codebase.
Currently I check for
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
to determine if which device is used. But now I want to check which app/target is used. In case someone uses the iPhone version on the iPad, I do not want it to be adjusted for iPad (the iphone version cost less so should not adjusted for ipad).
Upvotes: 1
Views: 257
Reputation: 15400
A good way to change your behavior in different targets whilst using exactly the same code base is to create a pre-processor definition and omit it in one of the targets or set it differently in each of the targets. Then your code can be compiled differently to alter its behaviour based on this definition (for example through conditional compilation if you use an #ifdef
directive).
Upvotes: 1
Reputation: 8526
If for the iPhone app target you set the target device family to just iPhone, UI_USER_INTERFACE_IDIOM()
will always return UIUserInterfaceIdiomPhone, even when on an iPad.
Upvotes: 0