Professional Documents
Culture Documents
The authors and publisher of this book have used their best efforts in preparing this
material. The authors and publisher make no representation or warranties with
respect to the accuracy, applicability, fitness, or completeness of the contents of this
program.
This manual contains material protected under International and Federal Copyright
laws and Treaties. Any unauthorized reprint or use of this material in prohibited.
Apple has done exactly that with its iPhone and iPod products, content delivery
mechanism and business model that has leveled the playing field between big,
small and individual businesses.
Those of us who move quickly to learn the technology are the ones who will
benefit the most from it, before ideas are taken by others and before the
market gets too saturated, making it harder to succeed.
You may have a very exciting idea and a passion to learn the tricks of coding
like the gurus, but the due to limited iPhone development tutorials online and
lack of well structured courses, your journey may probably not take off at all.
As a result, your idea that could become the next blockbuster application on
the App Store – will never happen and remain just a dream.
And, its not really your fault… as there are currently no affordable online
iPhone development courses that teach you through real tutors who guide you
through step by step.
Over a period of 12 weeks you will learn the topics step by step and start
coding like the iPhone gurus. We will teach you through the following mediums -
Weekly Online Videos that you can download and view at your convenience
Access to an Online Form for discussing issues and meeting other students.
Plus you get a full 30 days no questions asked full money back guarantee.
Before starting your journey, you must understand what is needed and
expected of you to finish the course successfully.
However if you are not a programmer, but are up to the challenge, then you
must ask yourself if you will be programming yourself - or will you go through
this course to eventually become a producer for an iPhone product.
I suggest that you try to learn just basic C or python to quickly learn the
programming nuances and concepts.
So, in order to get started comfortably with this course, you should be able to
understand the following concepts before you go forward -
I’ll stop at that, for now. This should be more than enough.
Either way … you need to do some homework before you start the iPhone
Programming course!
The iPhone Course is structured to teach you and focus on the following -
Objective C
iPhone SDK
iPhone APIs
Objective C
It was developed by Brand Cox and Tom Love for their company StepStone.
According to Wikipedia Objective-C is a reflective, object-oriented
programming language, which adds Smalltalk-style messaging to the C
programming language. Now if you don’t understand what is reflective, object
oriented and messaging there is no need to panic.
It will be discussed soon and you will cross these mole hills before you actually
climb the mountain.
Cocoa touch is Apple's name for the collection of frameworks, APIs, and
accompanying runtimes that make up the development layer of iPhone OS.
By developing with the Cocoa touch frameworks you will be writing applications
the same way that iPhone OS itself is written, with controlled access to the the
operating system. You need to learn various aspects of the touch framework to
master the iPhone programming.
The iPhone SDK consist primarily of Xcode and Interface Builder. The Xcode is
all season complete SDK for building MAC software. It has been extended to
support the iPhone and iPod programming.
The other tool that will be used very often is called the interface builder. It
helps creating faster interface for your application with minimal coding thus
reducing the development time considerably.
iPhone APIs
Additionally to Cocoa there are other libraries such as OpenGL es which you
need to learn to give your application that extra punch which can knock down
the competition.
The other iPhone specific components that you need to learn is SQLite , Core
animation, Accelerometer, phone and media playing APIs.
The first thing we need to do to get started is to setup our coding environment
on our computer.
For this, we need to download and install the iPhone SDK on our Mac or the
Virtual OS on our Windows PC.
Once the Xcode is installed, it will appear in the dock as shown below. You
need to click and start the Xcode to create your first application.
Alternatively, you can search for Xcode in Finder and can start things from
there.
Now, close the smaller window, and you are ready to start programming for
iPhone!
… and a new project template window will be displayed as shown on the next
page, below -
These templates are handy to use and more often than not, we will use
standard templates to create our applications.
However, if you do not need any hand holding and you want to create an
application from scratch, you may use the windows based application.
Xcode IDE primarily can be narrowed down to three major parts in addition to
the Menu. They are …
This customizable bar provides shortcuts to menu elements, and looks like
this…
This bar displays the directory structure of the current project. We will use it
more in a later part of our course. It looks like this …
The other major part is the code editor. The content area is where you write
your code. You can access the files from the side bar by clicking them and it
will show up in the content window.
When we created the views based project, Xcode create lots of code and
component for us. Let us have a detailed look into this code.
If we click on the Classes folder on the left panel we will see the classes that
have been created by the Xcode.
Hello_WorldAppDelegate.h
Hello_WorldAppDelegate.m
Hello_WorldViewController.h
Hello_WorldViewController.m
These are all Objective C files, each playing a designated role in the project.
Through in this article we will not get into the details of these files but, for
clarity of purpose, we will define the work assigned to these classes.
We know that “.h” files in objective C are for deceleration and “.m” files have
the implementation details. So the two classes Delegate and View Controller
are also divided into respective “.h” and “.m” files.
The Delegate class is the class which listens to the Applications running. This
class actually starts the application and exists all through the life cycle of the
application.
In short you can consider the Delegate as the Shell which enables the
application. Application passes messages on to the delegate through its life
cycle which is handled and acted upon by it.
The View Controller is very specific to view based application that we have
selected. Before we discuss the View Controller we must tell you that View is
necessary to draw content on the iPhone.
In fact each iPhone Application has one window and can have multiple views. A
view is drawn over a window and in most of our practical applications we will
be dealing with views only.
This architecture is similar to the MVC architecture where we use model view
and controller components to create our application.
Let us now have a detail look into the code generated by the Xcode. In order
for it to make any sense you must understand ObjectiveC.
However, even if you are not familiar with this, as of now, you can read
through it. We have briefly clarified most of the major concepts.
Now, let us talk about some important concepts which are there is the code
below
Now that you are familiar with the above concepts, here is the code snippet…
AppDelegate.h
@class Hello_WorldViewController;
@end
The Above delegate class starts with defining a class directive for view
controller.
As discussed above it does that to import the definitions from view Controller
class. The Next line uses a concept called as Protocol -
The key words “nonatomic” and “retain” decides the way the object is stored
and accessed. We will talk about them a bit later.
AppDelegate.m
#import "Hello_WorldAppDelegate.h"
#import "Hello_WorldViewController.h"
@implementation Hello_WorldAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
We start by importing the “.h” files. This is required for the compiler to
relate the objects to the corresponding class.
We then find a method which is first called as soon as the application starts.
The method “ applicationDidFinishLaunching” is created automatically the
SDK. This starts the application with the root window.
It then adds the view on top of the window with the key word
“addSubview”.
As our view is being handled by the object viewController the system added
addSubview:viewController.view.
The next method dealloc is to free the memory occupied by the objects we
created.
ViewController.h
#import <UIKit/UIKit.h>
@end
Currently this class has very few lines and it just declares itself as an
interface.
ViewController.m
#import "Hello_WorldViewController.h"
@implementation Hello_WorldViewController
////Some methods
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
Currently the code is not doing much except for being an empty
implementation file.
The methods that are there are empty and does not serve any purpose as of
now. We will now take this program to the next level adding an interface to
our application and we will do it by using Interface Builder.
To see it in action, in your side bar click the resources folder and click on the
ViewController.xib file.
The xib file is an interface file which is called a “nib file”. Once you double
click on the nib file it will automatically open the interface builder.
1. Component Window
At this point of time you can consider these element as components by which
the interface is created and rendered on a device. The File owner is the master
class and the interface we creates belong to the File Owner. The First
Responder is responsible of responding to user inputs done at the interface. We
will deal with them in detail in our later sections. The View is the actual
interface that will be visible to the user.
The library is the collection of interface elements like Label, TextBox and
even view controllers. You can create great applications just by using these
standard components.
View Attribute
Connection Attribute
Size attribute
Identity attribute.
If you want to have a look at these attributes, select the Inspector from the
Drop down menu and the window will appear in your screen.
We will learn to use this a little later. We will first complete our application
which will print “Hello World” on the window.
Go to the element label and drag it to the view window which is currently
gray in color.
Once your label is present on the view, you can clearly see the word “Label”
written on the view.
Simply double click on label and you can edit it to whatever you want.
Alternatively you can select the label and open up the Inspector. In view
attribute, that is first tab itself, change the text from label to Hello World.
Save the nib file and close the nib file by closing the component window.
So, now that we are done, we want to execute the first program we wrote!
In your Xcode top bar, click “Build and Run” and if everything is proper, you
will see the emulator appear and display the text… “Hello World” on the
screen, just as shown in the figure below…
As we have now successfully created our first Application we will try to extend
this application and will try and add a user event to it.
We will start by creating an IBOutlet for the label which we want to change
and an IBAction to interpret the user action.
#import <UIKit/UIKit.h>
-(IBAction)buttonPressed;
@end
The code above creates an Outlet of class UILabel to store the label object
which has been defined as *label.
We then make this object a property to automatically use getter and setter
functions later.
Open the library and drag a round rectangle button from the library to get
the following view…
Control drag from the File Owner to the Label which is now written as “Hello
World” and from the pop up that appears select “label”. “label” was the
object we created in our code.
To connect the IBAction we will select the button and open up the Inspector.
#import "Hello_WorldViewController.h"
@implementation Hello_WorldViewController
@synthesize label;
-(IBAction)buttonPressed{
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[label release];
[super dealloc];
}
@end
This completes our Application which displays hello world and then changes
itself based on the user command.
You may download the source code for the above project from the following
link - http://edumobile.org/downloads/Sample.zip
You must take advantage of the iPad launch and the benefits you can gain from
it. For this, you should definitely make your iPhone App compatible with iPad
also. The iPad went on sale in April 2010 in the market, and Apple created a
new section in iTunes that lists new iPad Apps or enhanced iPhone Apps that
are compatible with iPad.
All iPad users who have already downloaded your free or paid App to their
iPhone or iPod Touch will be able to download your iPhone App – only if you
have updated your binary submission to the App store to make your iPhone App
compatible with iPad. If you do not update and create the separate binaries,
then you are potentially losing out.
Using the new SDK you will be able to create a single binary which will install
one version of your app when used on the iPhone or iPod Touch and a different
binary when installed on an iPad. iPad development is an extension of iPhone
development and you must first learn iPhone programming, before you move on
to learning the new extended functions and features specially made for the
iPad. Some of the ways the iPad differs from the iPhone are…
Supporting rotation is a must on the iPad. This is because the iPad does not
have a normal way in which it will be held unlike the iPhone, which is normally
held vertically (portrait view). With the iPad the user can be comfortable with
both the vertical or horizontal (landscape) orientation. This means that your
iPad App has to support both orientations – that is, it must be able to rotate
and appear properly in both views.
View Controller -
All iPhone Apps which currently use UINavigator to switch to another view
showing details of something selected in a list, can now take advantage of the
new detailed view controller. This functionality will now provide simultaneous
viewing of the list and the detailed view – when in landscape orientation, or a
full-screen viewing of the details view with the list available in a popover view
– when in portrait orientation. All of the Apps will have to been rewritten to
use these new features and users will expect them of your applications as well.
You should use the UIKit functionality to build this into your App.
Popover views are not supported in the iPhone, but can be used to create
modal dialogs, modeless dialogs, and menus in the iPad. Hence, all Apps which
use the master/detail view, will automatically convert the master list to a
popover menu when the iPad is placed in the Landscape orientation. You can
use this same popover technology to create menus, such as shown in Pages and
modeless dialogs. An example would be the color picker shown in the Brushes
App, or creating D-pad controls. These popover views can easily be closed by
the user by tapping on any region outside the popover window boundary.
Hence, while designing, make sure you leave some areas on the sides where
the user can touch the screen to dismiss the popover window. Design cleverly
to see where you can replace entire views with Popovers. This will greatly
simplify your apps on the iPad and the speed and ease with which users can
navigate quickly. Don note that since the iPhone and iPad Touch do not support
Popovers, you will need to create and use a custom view for them – should you
use Popovers in your iPad App.
Tabs -
Tabs can appear on the top or at the bottom of the screen on the iPad. This
gives you the ability to provide more traditional tabs on the top of the UX
rather than just at the bottom. You can thus also put tabs in the top of your
Popover views.
TableView -
TableView controls can now have multiple columns. Therefore, try to eliminate
custom controls or provide an enhanced UX to your users.
The limited screen size of the iPhone and iPad resulted in limitations in the
possible touch screen finger gestures. With the iPad and its bigger screen, a
whole new set of gestures are possible. There is plenty of space for long-touch
and also drag gestures and multi-finger controls ( the 3-finger twist gesture ).
You can see Steve Jobs doing this in the Developer Keynote Speech.
Also, since the iPad screen is large, Apple has built in a functionality that
supports multiple users touching different parts of the screen at the same
time. For example 2 people can play a game of hockey-puck with each other.
The iPad screen is hence large enough to allow different simultaneous gestures
Multimedia -
If you create video content areas, you do not have to display the video across
the entire screen, and you can restrict video to only a small portion or area of
the screen. This functionality can be used to combine the user experience with
multiple multimedia functionality.
The iPad supports mounting a shared file directory by connecting the iPad via
USB to a PC or Mac. This means you can easily share data files between your
devices if required by the App.
The iPad also supports wireless headsets and microphone, thus allowing total
hands-free voice-driven control of Apps.
The iPad has an optional “video out cable” – that you can use to project the
screen in full or part. This is fantastic for making presentations.
Using CoreGraphics, all Apps will now be able to generate PDF content. This
will allow you to generate reports in PDF should you App require this.
The Compass and Location / GPS functionality is only available in the higher
models of the iPad that support 3G. While developing you should make sure to
check for compatibility so that you can enable or disable the feature, as
appropriate.
Each text input field (using the TextView function), will support spell checking
and auto-completion by default – just as in the iPhone. You can define if you
want to auto-enable or disable this functionality.
You can also implement multiple custom virtual keyboard layouts within a
single App, thereby displaying different types of custom keyboard inputs like
Scientific keys, I.P. address keys etc. for TextView controls as needed.
Avoid undesirable uneven image stretching of your App when users change the
orientation of the iPad. The iPad is 1024 pixels in the tallest dimension and 768
pixels in the shortest dimension. These proportions are not the same as with
the iPhone or iPod Touch – and differ slightly. At the tall end the screen is
2.13x the size of the iPhone or iPod Touch. At the short end the size is 2.4x the
size of the iPhone or iPod Touch. Therefore, this slight disparity in proportions
will cause your view to stretch unevenly if you display it in full screen on the
iPad. You will therefore need to customize this view, if required for the iPad,
in order to avoid any uneven full screen resizing.
Step 1: Open the Xcode and create a new Xcode project usingView base
application template. Give the application name “Button Fun iPad”.
#import <UIKit/UIKit.h>
-(IBAction)buttonPressed:(id)sender;
a) Open the View window, first drag the label from the library and place it to
the view window and select the label and bring up Attribute Inspector and
delete the text.
b) Next drag a Round Rect from the library and place it to the view window.
double click the Round Rect and give the name “ClickMe”.
c) Now connect the File’s Owner icon to the View icon and select view.
d) Connect File’s Owner icon to label and select ”statusText”.
e) Select the Round Rect from the view window and bring up connection
Inspector.Drag from the TouchUpInside to the File’s Owner icon and select
buttonPressed: action. Now save the Button_Fun_iPadViewController.xib file,
close it and go back to the Xcode.
-(IBAction)buttonPressed:(id)sender
{
NSString *newText = [[NSString alloc] initWithFormat:
@" Hello World!!!"];
statusText.text = newText;
[newText release];
}
You can download the SourceCode from here Button Fun iPad
This was a small step in our journey towards getting started with iPhone
development. If you are interested in learning iPhone and iPad Development,
we suggest you sign up for our complete 12 Week iPhone Programming
Course at the link below. It comes with a full money back guarantee, so there
is no risk at all.
You will be assigned your own personal one-on-one tutor, whom you may
consult any time with questions and problems you face.
The course is delivered over a period of 12 weeks via Online Video that you
may download and view at your convenience, along with material and Weekly
Worksheets.
You will also get access to our private forum where you can meet other
fellow iPhone developers.
Click Here To Learn More About The iPhone Course and To Enroll
Affiliates Join Our High Paying Affiliate Program and Make Tons Of Money!