Anyone has a tutorial on how to create Universal a

2020-07-10 09:12发布

问题:

It looks like things changed with XCode 4.2 and I did not see any guide/tutorial on how to create a Universal app with XCode 4.2. Anyone knows one or wrote one?

Note: I'm not talking about how to select your project to be Universal, I'm talking about a Hello World tutorial.

Thanks,

回答1:

In case you actually wanted a plain source, compilable as a universal app that writes Hello World into the console, depending on the device in use, here comes a tiny snippet for you.

main.m

#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        printf("hello world, from my iPad");
    }
    else 
    {
        printf("hello world, from my iPhone or iPod");
    }
    return 0;
}

Within the build settings of your app, you will have to select:

TARGETED_DEVICE_FAMILY = 1,2

Like this:



回答2:

  • File / new / new project / ios / application / single view application
  • Next
  • fill fields and choose "Universal" in Device Family
  • Next

Xcode will create a project with 2 initial XIBs with same names and different suffix _iPhone and _iPad.

Enjoy!

Good luck!



回答3:

Look for any Hello World iPhone OR iPad app. Make sure you set the project to Universal.

  • iPhone: http://www.tuaw.com/2009/04/27/iphone-dev-101-the-hello-world-app/
  • iPad: http://hijinksinc.com/2010/07/23/entry-level-xcode-hello-world-for-ipad/


回答4:

Try :

Head First iPhone and iPad Development, 2nd Edition A Learner's Guide to Creating Objective-C Applications for the iPhone and iPad By Dan Pilone, Tracey Pilone

They have a great section on Universal Apps :)