Having iPhone & iPad Perform Different Actions - iphone

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.

Related

Converting IPad App to Universal App

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

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"]

iPhone locked Portrait, iPad locked Landscape

I'm trying to convert an iPhone app to iPad. The tricky things is that the iPhone app has to be locked to portrait view and the iPad app has to be locked to landscape view. I'm kind-of a noob at interface builder so I'm a little lost.
Any help is greatly appreciated. Thanks!
You need to override shouldAutorotateToInterfaceOrientation. A good place to put this is in the app delegate.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
return YES;
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
return YES;
}
return NO;
}
I'm not sure, but this may also support the phone being upside-down, which is a HIG no no. You might want to use interfaceOrientation == UIInterfaceOrientationPortrait instead for the phone.
You should have two nibs and load them separately depending on which device your application determines it is running on: one for the iPad and one for the iPhone. You can then set the orientation easily. NB: The iPad app should support all orientations variants (ie. if you support portrait, support portrait upside-down) and will most likely get rejected by Apple unless you have a compelling reason as to why it shouldn't.