Make an application work on both iPhone and iPad - ios

I would like to make it so that my iPhone app also works on iPad.
If I run it using the iPad simulator it does work, but the app doesn't show up on the iPad app store, and looks really weird.
Is it possible to create another .xib file for the iPad? I know how to add a new iPad .xib file, yet I don't know how to actually change the RootViewController.xib to RootViewController_iPad.xib if the device being used is an iPad.
I already have code for finding out if the device is an iPad, and I don't want to use auto-layout, because I would like to add different things to the view if they are using an iPad (such as using different images).
I would like to make it so that my iOS applications look good on both iPhone and iPad, and have a separate .xib files for each. Is it possible to change the default .xib file from RootViewController to RootViewController_iPad?

In order to make an application work in both iPhone & iPad then need to follow below steps.
Before create an project please select universal in device section.
In application: didFinishLaunchingWithOptions: put a condition to check the device.
If the device is iPad then load the iPad screen and if the device is iPhone then load the iPhone screen.
Make sure follow the MVC pattern, So that it is easy to populate the data in both the screens.

#class has no effect on outlets or actions it only tells the compiler that there is a class with the name that follows, no information about properties, or methods is included.
If you want to have a xib for the iPad don't create a new class for it, just create a new xib and set the file's owner to be the same as the what owns iPhone xib. You then need to add a check in application: didFinishLaunchingWithOptions: to load the correct xib.
The best option though is to tell Xcode you want a universal app when you create the project.

The key point here is that it must be a UNIVERSAL application. Its a setting when you set the app up for the 1st time. You will end up with 2 UI's (story boards or xib files).
You will have to create 2 seperate UI's for ipad and iphone. You may be able to use the main class itself for most of the code but then you have to basically put code that says
if its iphone.....
if its ipad ......

Related

iOS - Open a different Stroryboard based on the device size

I have created an app in Swift and I want it to be available in both iPhone and iPad, but I would like the iPad to have a couple different layout variables, such as bigger buttons and pictures. Using auto-layout or Size Classes with constraints wasn't working and not letting me put them where I want them, so I was wondering how to make it so that when I open the simulator with an iPad, it opens the storyboard with the different View Controller layouts. I made a duplicate storyboard so I have main.storyboard and the copy is mainiPad.storyboard for the iPad only. If this can be done, please let me know! Thanks!!
This Tutorial is the old way, when You simply add iPad suffix in the file name.
This Post is the new way, introduced in Xcode 6; You simply select the storyboard name for ipad and iphone family in application plist file.

Universal app iPad to iPhone

I have created an Universal app. I have designed the app for iPad. But it doesn't work in iPhone. Will it work automatically or do i have to create all nibs separately for iPhone.
Of course it will not work automatically, if your design is for iPad only it will not work on the iPhone.
You will have to create separate XIBs for the iPad and iPhone, you can use the same viewController (.h and .m file) but seperate XIBx. Just add the device modifier to the file: MyViewController.xib and MyViewController~iphone.xib or MyViewController~ipad.xib.
Ofcourse it will not work for iPhone by itself. But its not difficult to add the support for iPhone.
Create a new StoryBoard for iPhone. Then open your iPad StoryBoard, the one you already created. Select all and copy. And then open iPhone StoryBoard and paste it in. All the controls and everything you have done in the iPad StoryBoard will be added to your iPhone StoryBoard.
After that you can do modifications in iPhone StoryBoard like remove or add some new controls etc.
Hope this helps!

IOS: app universal concepts

I'm starting a project that must be for iPhone and iPad...you can tell me that it's easy and that I can create an "Universal" project..it's right.
But I have a "stupid" question about a "stupid" problem.
In an universal project I have two .xib (iPhone and iPad) for a class and inside code I verify if I'm using the one or the other
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad running iPhone 3.2 or later.
}
else
{
// The device is an iPhone or iPod touch.
}
ok?
But you know that in a single view of iPad I can show many views that an iPhone can show one at time.
At example I have two view with their classes:
FirstView.h-FirstView.m-FirstView_iPad.xib-FirstView_iPhone.xib
and
SecondView.h-SecondView.m-SecondView_iPad.xib-SecondView_iPhone.xib
For iPhone it's not a problem but for iPad? In a view in iPad I can put first and second viewcontroller, it's not easy to organize if I have two different classes for two viewcontrollers... Do you have a solution for this? Or the best solution is crate two separate project iPhone and iPad?
thanks
So yeah I always use one theViewController.h and one theViewController.m and I have a theViewController.xib for iPhone and a separate xib for iPad only. if you name the iPad xib ending with theViewController~ipad.xib the OS will automatically recognise the XIB. You will have to set the class of the theViewController~ipad.xib in Interface builder in the inspector area to the same class as your iphone xib i.e the class would be called theViewController then you can connect up what ever outlets you have defined in your .h and .m also the great thing about just naming the iPad xib to ending with ~ipad.xib when you push views you dont have to check the idom before pushing as the OS recognises the ~ipad.xib extension and pushes the correct view depending on device..hopefully this is helpful for you!

Different XIB files for iPhone 5 automatically

I am updating my app to support the new iPhone 5.
I was wondering if there's any sort of way that you can create a different XIB file for the iPhone 5 that will load automatically, like when images with "#2x" in the end are loaded automatically when an iPhone 4 is used, without having to make any changes to the code itself.
Thanks!
As I know, there is no simple way to load correct xib for iPhone5 without extra code. However, i can suggest this simple class for detecting iPhone5. In addition, there also is a category for selecting correct image for iPhone5 here. You can do the same for initWithNibName:bundle: method.

iPad: app with TabBarController not working

I have an iPhone app that works just fine on the iPhone. I am trying to get it to work on the iPad (v 1), but it won't move off the first view.
I have a TabBarController with 5 views. When I tap on the other views, they don't show. Is there something I need to do differently when using a TabBarController for the iPad?
BTW, it doesn't work on the similator either...
I'm making an assumption here but if you originally designed it for the iPhone only and want to convert it to a universal app for both iPhone and iPad, you will need to have two MainWindow.xib files. One for the iPhone and another for the iPad. And you'll have to specify those .xib files in the project settings. Set the Main and iPad interface files. An easy way to get a version of the iPad MainWindow.xib is to create a new project for the iPad and just copy it over to your own proj.

Resources