Removing default window nib in a window based application

When creating a window based application in Xcode4, it usually create an unwanted nib file that represents the default clear white window.

Note: your class names will probably be different then mine, try to keep up, its not that hard.

Some times we want to remove it and replace it with are own view controller, here is how:

  1. delete the default MainWindow.nib. You can totally delete it, assuming you have no information in it.
  2. Click on the project (above the files – blue strip) and select the target. on the right, go to info, locate the “main nib file base name” line and remove it entirely. You can run your application now with no errors (and no output…).
  3. I assume that you have created a view controller. if not create it now. Go to your app delegate file header and import the header for your master view.
  4. declare a property for that controller and synthesize it on the m file.
  5. now we need to create the default window: self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; add this to the application didFinishLaunchingWithOptions function. BTW – the reason that we didn’t get an exception so far is because once the main nib is deleted, the entire application function will not be called.
  6. next, create the nib file: mainController=[[SwitchViewController alloc]initWithNibName:@”MainView” bundle:nil];
  7. then, assign the master controller to the window: [self.window setRootViewController:mainController];
  8. Now, the application is not even aware at this point of its delegate. This is bacause we delete the main nib file, so changes must also be done to the main.m file, hiding sometimes in the supporting files folder. this is actually very simple – just feed the UIApplicationMain function the delegate it deserves! So, instead of the default UIApplicationMain(argc, argv, nil, nil); replace the last nil with your class delegate name, like so: UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

Now it’s working

NSStringFromClass gives a string… from the class. which is what this function requires, in case there is no nib file that loads that data for us.

 

Main differences between Android and iOS development

If you want to develop, or hire a developer(ahhhm…) to develop mobile application, these are the two big choices. Other options are: Nokia Symbian, Windows mobile, the RIM blackberry and some other platform that are not used by the major public.

For the sake of this document, I’ll focus only on the first two, which are the dominant ones at the moment. I will go point by point, specifying the differences between these two.

Why developing an application?

Before reading more, do you even need an application? If what you want can be achieve with a web site, you might want to stick to that, and wave the application. If what you need is an information page, web page will do the trick, however, there are many reasons to build a custom application:

  1. Information control – if you have a lot of information on a site (Facebook, anyone?) most devices will have a hard time rendering heavy web content.
  2. Usefulness. if you want to use the phone additional capabilities.
  3. Speed – apps will run faster and performs better.
  4. User access -the user will access application more – that’s obvious.
  5. Special GUI features – This is one of the main reasons to have an app – you want to enable the users to interact in an easy, fun, and fast way.
  6. Real world applications that can not be done on a web page, and there are many examples of this – server controllers, diet calculators, camera viewers, security monitors and so on.
  7. Marketing value – it looks  much more professional to have your client downloads your application and have your icon on there desktop. many banks and internet provider do just that, even they can saddle for a web page. The application gives a certain “extra” touch.

If you answered yes to one of the above, you need an application.

 

Market

Both iOS and Android have an open market where the users can select and install programs, either free or paid for. In both cases you must register in order to publish your application to the public. In both cases payed application will require extra setup. Company account will take longer to set up, in both. However, apple  setup usually takes longer, in both scenarios. You can have an already registered developer post your application for you (especially if this is a free one) however, it will appear under his account.

Development

iPhone uses Objective C which is horrible (sorry, but it is true), crippled language, that in spite of what some people say is not really object oriented. However, you can add C++ code to apple project very easily, which xCode supports fully. However – the C++ code can not be used for apple library calls or OS calls, but you can create you own classes. Apple uses Xcode as development IDE, and, apple development can be done only on Apple computers (if not considering some third party tools). Apple have only one product, iPhone (not referring to the ipod) and if the iOS version is right, the application will run – as long as the iOS installed is higher or equal to the application requirement.

The Android on the other hand, uses Java which is 100% object oriented, uses eclipse as the IDE, that can be installed on any Major OS – Windows, Linux and Mac (yes, even Mac). However, Java is Java, and it does not output machine code, so it might take a longer to load since it does need second compiling. The Java platform was selected in order to support a wide range of phones, and it does.

giving these differences, Apple application might be more expensive to develop.

Permissions

Both OS limit the permissions a developer can have, But in a very, very different way. on Apple, the iOS will enable you to access the internet, create a local private DB and files, get the GPS location (the user have to approve this) access to the contact list (user have to approve this), send (through the regular SMS UI) but not receive a text message and that’s about all. If you see application that can do more, it is running on a jail broken device, in which you can do whatever you want, but we are not referring to these. for most applications these limitation are OK, and they can execute well. on Android, you have to define permissions when writing the application. The user will see them when he or she installs the application and can decide then if he wants to install it or not. If the developer didn’t ask for a certain permission – he won’t be getting it later on. In Android, developer have to ask for permission to do almost anything, including accessing the internet. However, he can also get access to GPS data (same as iPhone) SMS data (not applicable on iPhone) Calls data (not applicable on iPhone), can start services at boot time (not applicable on iPhone) and change many system aspects (not applicable on iPhone). The beauty of it all – the user view all of these permissions at install time. if he doesn’t approve, he can wave installing this application. If he choose to install it, he agree to give that application the permissions it asked for, and he will not be bothered with them later on.

Deployment

To deploy an apple iOS application, you must have an apple ID. You must code sign your application with apple and post it to the app store (there are some cases that you can distribute them yourself, but only for a small user group). In Android, you can send your application by mail, have it on a web site (many vendors do) without any contact with Google. to publish to Google market, you do need to have an account. The signing process however, is much simpler, as the signing up process.

Ratification

On Apple, every application submitted to the app store is going through a ratification process, in which the application is reviewed be apple. The amount of time taking to do that varies, and only after the application was approved it will go to the store. This process is done for every application, and will be done repeatably for every update this application may have. On Android, the application will be submitted automatically. if the users won’t like it, they will just remove it…

Basic iOS application

Unlike Android development, for iOS development you must have an apple computer (or equivalent…) running Mac OS on intel platform (that is, not an old one). the development tool for apple is Xcode, I’m assuming you got it all working and installed.

firing Xcode 4, this is what you will see (4.2 has a different start screen): You can select from many application types, the one selected is the simplest one, the Window based application. Lets select this one, in the next screen we select a name for this project, and a company identifier. The last is critical for submitting to the app store, however, it can be changed, so you can set it to whatever you want. It’s usually takes the course of a reverse domain name, as in the image below:

You can select device family, but we will leave it at iPhone. Core data is for local DB programming. Next you are asked for a location, and that’s it – you  are all set. You end up with the production screen.

Go and click Run. Xcode should build your application and start the simulator (unlike android, which uses an emulator). if you are getting an error, make sure you have no iOS device connected, and that your SDK architecture is set up (click on the blueprint icon, then to the right the other blueprint icon that change the Base SDK value to iOS XX).

Now, you do have an iOS application, that does… nothing.

lets click on the MainWindow.xib and add a label (all the GUI stuff are located in the right bottom corner. if you can’t see it make sure the right pane button is pressed)

Next, Drag a label and set the text property to Hello world!. You  can resize the label if it got to small. Run again.

Congratulation! You just created your first iOS application.