We currently have an app that targets the IPad. We now would like to target the IPhone aswell. Im just wondering how we go about this? UI layout and functionality will be different but under the hood they will be sharing a lot of the same code.
Am I best creating a Universal app? or having to seperate apps one for the ipad and one for the iphone?
Any help will be greatly appreciated.
Thanks
Use these two macros
#define FOR_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define FOR_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
if(FOR_IPAD)
//load view for iPAD
else
//load view for iPhone
Related
I want the WebView to display a specific URL based on the device the user is using. For example:
if(deviceType == iPad)
{
// Load Site on iPad & Retina iPad
[webView loadRequest:[URLWithString:#"http://site.com/ipad.html"]];
}
else
{
// Load Site on iPhone & Retina iPhone
[webView loadRequest:[URLWithString:#"http://site.com/iphone.html"]];
}
How would I go about doing this? Thanks :)
Use something like:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
UI_USER_INTERFACE_IDIOM() is a macro that calls the userInterfaceIdiom method of UIDevice, with a fallback if that method isn't available.
Should I make 2 separate app delegates for a universal app? One myAppDelegate, then myAppDelegate_iPhone and myAppDelegate_iPad which are subclasses? Reason being iPhone should have IBOutlet of NavController while iPad should be UISplitViewController.
Also, how do I separate actions between iPhone and iPad. For example, a button on iphone may push a view, but on iPad i want to have a small window popup instead rather than a full-screen push. Do I just use a if/else statement to check if iPad (by uiswitchviewcontroller), then go from there?
if (NSClassFromString(#"UISplitViewController") != nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//currentDeviceType = iPad;
}
else {
//currentDeviceType = iPhone;
}
This question seems to be along similar lines.
Universal iPhone/iPad AppDelegate
This doc from Apple might also prove helpful.
Introduction to Universal Apps
No need to take two separate application delegates. You can code on the condition...
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){}
This will automatically detect the device.
To enable rotation on the device, you need to return YES to
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
FOR ALL OF YOUR VIEW CONTROLLERS.
You should also add your supported orientations to your plist or info under xcode 4.
Also keep in mind that stack overflow prefers that a new question be asked when the question topic changes :)
am a noob at universal apps so please help me out and let me know if this can be done, I am creating a universal app and for doing this i have written the code and made the settings in each of my view controllers present in the iPhone and iPad group and at runtime i am identifying the device whether its iphone or ipad i am using the below method
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
myiPad_View *ipadObj = [[myiPad_View alloc]init];
[self.window addSubview:ipadObj.view];
}
else
{
myiPhoneView *obj = [[myiPhoneView alloc]init];
[self.window addSubview:obj.view];
}
Now the query is my boss is eating my head for this he is telling me that can we write just one class and at run time when the app will be launched either in iphone or ipad device or simulator the view controller will adjust the frames accordingly i have done this by using the above method but he says if you do like this then the code will increase and you have to suffer a huge headache so actually he is right but haven't found of any alternate solution to this, so before saying this cant be done i thought of taking some expert advice
Your above method is actually how I determine devices in some of my apps as well.
I actually recently wrote a little piece on this issue.
You can also use:
#define IDIOM UI_USER_INTERFACE_IDIOM()
#define IPAD UIUserInterfaceIdiomPad
#define IPHONE UIUserInterfaceIdiomPhone
if ( IDIOM == IPAD )
NSLog(#"Device is iPad.");
else
NSLog(#"Device is iPhone or iPod touch.");
or
if ( [[[UIDevice currentDevice] model] isEqualToString:#"iPod touch"] )
{
NSLog(#"Device is an iPod touch");
/* same goes for "iPhone", "iPad" etc. */
}
I have 3 sets of classes:
base classes: this is where the shared logic goes
iPhone classes: iPhone specific logic including UI goes here
iPad classes: iPad specific logic, including UI goes here
I have as much as possible in the base classes, but for the times when the logic is separate, it is much easier to have the distinct classes. Digging through the code looking for the exceptions would be a pain, IMO.
I found this blog helpful (not mine)
Its not a problem . you have to create a universal app.
File--->New Project--->windowsapplication
and then choose a product Universal.
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;
}
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"]