2

I have two complete projects. One works on iPhone and the other works on iPad. I want to merge these into a Universal app.

So far the only solution I have is to rename app the classes with '_iPhone' and '_iPad' suffixes and change all references to those in the code. Then I could merge the AppDelegates and load the correct controllers at launch.

These are two very big projects so this method is going to be very time consuming. Does anyone have a better solution?

  • Some user do a similar question once http://stackoverflow.com/questions/5280407/is-there-a-global-way-to-merge-an-iphone-and-an-ipad-app-into-a-universal-app . – LuisEspinoza Mar 15 '12 at 18:49

2 Answers2

2

Your drafted solution seems to be the only option I know of - curious to see other answers.

One thing though; you could actually keep two separate AppDelegates.

Within your main-implementation, you could check the device and launch either the iPad-AppDelegate or the iPhone-AppDelegate.

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = 0;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        retVal = UIApplicationMain(argc, argv, nil, @"XXXAppDelegate_iPad");
    }
    else 
    {
        retVal = UIApplicationMain(argc, argv, nil, @"XXXAppDelegate_iPhone");        
    }
    [pool release];
    return retVal;
}

In most cases however, I would advice to rethink such solution - often enough this results into inconsistencies and/or code replication. Still, I thought I should point out the option.

Till
  • 27,559
  • 13
  • 88
  • 122
  • I was aware of that option but I don't like messing with Main.m. In Apple's latest iOS templates they do everything in one AppDelegate so decided that would be best. Thanks for the answer. –  Mar 15 '12 at 19:08
2

well as far as i know the only solution to do that is to create a new universal project and put your files there .. since there is a lot of share code between iPhone and iPad you can check what the device is used to running your app by check if UI_USER_INTERFACE_IDIOM()is UIUserInterfaceIdiomPad or UIUserInterfaceIdiomPhone .. and for the rename the easy way to do that to highlight the class name and select Refactor>Rename and xCode will take care about rename class name in every where you used it.

Malek_Jundi
  • 6,140
  • 2
  • 27
  • 36