App that works on both IPad and IPhone - iphone

I was just wondering if there is a way to create an app in XCode that will detect whether it is being run on and IPhone or and IPad and select different views to suit the platform?
i.e. Pseudo Code
//IF CURRENT DEVICE IS IPHONE THEN
//SHOW IPHONE MAIN MENU VIEWCONTROLLER
//ELSEIF CURRENT DEVICE IS IPAD THEN
//SHOW IPAD MAIN MENU VIEWCONTROLLER
Thanks in advance

Yes
it is called a "Universal App" and there is aTemplate for that project when you set a new "Window Based Application" in xcode.
to test if the device is ipad or iphone you can use this macro:
- (BOOL)isDeviceAniPad {
#ifdef UI_USER_INTERFACE_IDIOM
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#else
return NO;
#endif
}
shani

Related

Event touch up inside work in iphone but dont work in ipad ios6

This generate the error
Generate a project for iphone only with orientation landscape left and landscape right
Add a button to the interface builder
Run on the ipad simulator
Press the button and it does not work.
What can i do?
This solved the problem for orientations in ios 6
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Implementing the supportedInterfaceOrientations method in the ViewController does not help.
Kind of workaround would be to chose "Universal" (iPhone + iPad) as target device.

Creating universal app for Xcode 4.3?

I am little bit confused about creating universal application for iOS devices using Xcode 4.3 , later versions (Xcode 4) have separate folder classes for this, but how will we make this using newest version of Xcode?
Thanks in advance
I don't think this has changed in Xcode 4.3 compared to previous versions of Xcode 4.* , but though you have a doubt refer to my answer below.
If you want to create a new project as Universal App then select Universal in Device Family in below image:
Or if you are trying to convert an existing iPhone or iPad app to Universal app then select Devices as Universal from Target Settings- > Summary Tab, set Devices to Universal:
Hope this helps you.
EDIT:
Let us suppose View Controller name is YourViewController
Let us suppose name of iPad XIB is YourViewController-iPad.xib and iPhone xib name is YourViewController.xib
YourViewController *yourViewController;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //This is iPad
{
// iPad-specific interface here
yourViewController = [[YourViewController alloc] initWithNibName:#"YourViewController-iPad" bundle:nil];
}
else // This is iPhone or iPod
{
// iPhone and iPod touch interface here
yourViewController = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
}
Let me know if you need more help.
just select device family as universal while creating the project,
watch this screen shot
well you need to create two xib's, one for iPhone and one for iPad and just use
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
here open your iPad xib
} else {
here open your iPhone xib
{

different status bar style for iphone/ipad in universal app

I recently updated my iPhone only app to an universal app and successfully submitted the update to the appstore.
however, the UI-Designers behind the project would like to have individual status bar styles for each app. So the iPhone UI should have a solid black status bar where the iPad implementation should have it semi-transparent.
is there a way to tweak key/value-pairs in the info.plis file to achieve something like this?
thanks a lot for your ideas,
sam
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad running iOS 3.2 or later.
}
is recommended way of testing the device is iPad for iOS SDK >= 3.2
Use UIDevice class to get device model type in your application
NSString* deviceType= [[UIDevice currentDevice] model];
NSString* iPad = [NSString stringWithString:#"iPad"];
Now set the style of your status bar as per the model.
if([iPad compare:[deviceType substringWithRange:NSMakeRange(0,[iPad length])]] == NSOrderedSame )
{
//This is iPad
}
else
{
//This is iPhone/iPod
}

iphone to ipad xib file change

I have the two xib files 1.main 2.language translator this is a iphone app.
I want to change UNIVERSAL APP. i upgrade the universal application. now automatically created mainwindow-ipad.xib.
i run this app in xcode 3.2 version but it display left corner only .
how can i change this app to universal ... its big headache to me.. anyone help me
Thanks in advance,
Suresh.m
Check whether app is on iPhone or on iPad and accordingly load the nibs, I mean u have to keep the Ipad versions of ur interface builder files and load them according to the target device
if([[UIDevice currentDevice]interfaceIdiom]== UIUserInterfaceIdiomPad)
{
//Load ur ipad nib file
}
else
{
//Load ur iphone nib file
}
I usually create a new universal project, and then "move" my code into the template provided. I find that much easier then trying to flip all the other knobs.
I found iphone_bharat's example interesting, but it has a small type so I had to fix it and clean it up a little bit.
+ (bool)iPad
{
// Can use UI_USER_INTERFACE_IDIOM() for iOS less than 3.2
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad )
return YES;
else
return NO;
}

iphone - Detecting what type of simulator

how can I detect whether I'm using iphone simulator or ipad simulator.
I'm using some 3rd party library to which I've to pass a parameter whether i'm using ipad or iphone. in order to test the app, i want to programatically detect whether i'm using iphone simulator or ipad simulator. is there any way to identify it?
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// iPad code
}
else {
// iPhone code
}
did you tried [[[UIDevice currentDevice] model] hasPrefix: #"iPad"]