different status bar style for iphone/ipad in universal app - iphone

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
}

Related

Having iPhone & iPad Perform Different Actions

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.

Universal Apps concept for iPhone and iPad

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.

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

App that works on both IPad and 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