Making 2 Separate App Delegates For Universal App? - iphone

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 :)

Related

How to adjust app size when converting an iPhone app to a iPad app?

I have made a iPhone app that is on the app store. It's a simple view based application. It does have several XIBs and images. I have taken the necessary steps to convert the app to the iPad. It runs on the iPad simulator, but the size is too small. How do I adjust the size of the iPhone app for the iPad? If I need to do it by code, where would I implement the code?
Configure springs and struts in Interface Builder.
If that is not enough make device-based adjustments in code. E.g.
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) /* iPad */
{
self.someView.center = CGPointMake(100, 100);
}
else /* iPhone, iPod */
{
self.someView.center = CGPointMake(200, 200);
}
Typically, you would do that in controller's viewDidLoad method.
If you transitioned your iPhones target to iPad in Xcode it will have duplicated all xibs. You can open the -iPad versions in IB and realign everything from there. Programmatically, you can query the user idiom and position things differently depending on whether the current idiom is iPhone, retina or iPad.

Is it possible to create universal app without separate xib except MainWindow.xib..?

Since last few days i have been searching and think about universal app conversation. I came to know that in Xcode 3.0 there is the UIViewAutoResizingMask property and you can convert your app into universal app with single xib. So, if anybody know this way than please help me.
Yes.
If you can't adjust the interface using springs and struts make device-based adjustments in code. E.g.
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) /* iPad */
{
self.someView.center = CGPointMake(100, 100);
}
else /* iPhone, iPod */
{
self.someView.center = CGPointMake(200, 200);
}
I believe that with objects such as tableview, navigation bars and tab bars etc, when in universal mode, these are automatically resized if using the same view. The only problem I might see is those objects such as buttons and the resizing it relocating of these. I myself am not sure about this, but I'm sure that there's a way of doing so in the same view.

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 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.