Development of an iPhone business application

powerfuelΛογισμικό & κατασκευή λογ/κού

9 Νοε 2013 (πριν από 3 χρόνια και 9 μήνες)

192 εμφανίσεις

Universität Ulm
| 89069 Ulm | Germany
Fakultät für
Ingenieurwissenschaften
und Informatik
Institut für Datenbanken und
Interaktive Systeme
Development of an iPhone business
application
Diplomarbeit an der Universität Ulm
Vorgelegt von:
Andreas Robecke
andreas.robecke@uni-ulm.de
Gutachter:
Prof.Dr.Manfred Reichert
Prof.Dr.Peter Dadam
Betreuer:
Rüdiger Pryss
2011
Fassung February 3,2011
c
￿
2011 Andreas Robecke
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0
License.To view a copy of this license,visit http://creativecommons.org/licenses/by-nc-sa/3.0/de/or
send a letter to Creative Commons,543 Howard Street,5th Floor,San Francisco,California,94105,
USA.
Satz:PDF-L
A
T
E
X2
ε
Contents
1 Introduction 1
1.1 The H-Index.....................................
2
1.2 The G-Index.....................................
4
1.3 Acceptance of the indexes.............................
5
1.4 Google Scholar as the data source........................
6
2 iPhone Development Introduction 9
2.1 XCode,Interface Builder and the iOS SDK....................
9
2.1.1 XCode....................................
10
2.1.2 iOS SDK..................................
10
2.2 iPhone Limitations.................................
11
2.3 Objective-C and MVC...............................
12
2.3.1 Memory Management...........................
12
2.3.2 MVC on the iPhone............................
16
2.3.3 Communication between objects.....................
17
2.4 User Interface Design...............................
21
2.4.1 More on Interface Builder.........................
21
2.4.2 Coding user interfaces vs.Interface Builder...............
27
2.4.3 Human Interface Guidelines........................
29
2.5 Review Guidelines.................................
30
2.6 Test your app on the device............................
31
3 Requirements 35
3.1 Requirements defined before implementation..................
35
3.1.1 Calculation of h- and g-indexes......................
35
3.1.2 Manage search results...........................
35
3.1.3 Merging publications............................
36
3.2 Requirements emerged during the implementation process..........
36
3.2.1 Graph Feature...............................
36
3.2.2 Comparison Feature............................
37
3.2.3 Remember Feature............................
37
4 Architecture 39
iii
Contents
4.1 Controller Hierarchy................................
39
4.1.1 UITabBarController Class.........................
39
4.1.2 UINavigationController Class.......................
40
4.1.3 Custom controllers loaded through the MainWindow NIB........
44
4.2 Custom Controller Inheritance...........................
44
4.2.1 UIKit Controllers..............................
44
4.2.2 Super Controllers..............................
44
4.2.3 Custom Controllers.............................
46
4.3 Parsing and Database Functionality.......................
46
4.3.1 Parsing...................................
46
4.3.2 Database Access..............................
47
4.3.3 Outsourcing parsing to a server......................
49
5 Implementation 51
5.1 Calculation of h- and g-indexes..........................
51
5.1.1 Development of a Google Scholar API..................
51
5.1.2 Analysis of the HTML document structure for parsing..........
57
5.1.3 Choosing a parser.............................
62
5.1.4 Calculation Algorithms...........................
69
5.1.5 The Search Flow..............................
70
5.2 Manage search results...............................
73
5.2.1 Displaying the calculated indexes.....................
73
5.2.2 Emailing results..............................
74
5.2.3 Displaying the publications of a search..................
77
5.2.4 Editing results...............................
81
5.2.5 Displaying a publication..........................
82
5.2.6 Data persistence on the iPhone......................
85
5.2.7 Caching and Saving............................
87
5.2.8 Manage stored results...........................
88
5.3 Merging publications................................
90
5.3.1 Merge Mode................................
92
5.3.2 Merging...................................
93
5.3.3 Dissolving..................................
93
5.4 Graph Feature...................................
94
5.4.1 Displaying large Images..........................
97
5.4.2 Quartz 2D..................................
98
5.4.3 Graph drawing strategy..........................
98
5.4.4 Creating an image file...........................
99
5.4.5 Email the image..............................
100
5.5 Comparison Feature................................
100
iv
Contents
5.6 About and Instructions...............................
102
5.7 Remember Feature.................................
105
5.8 iOS Frameworks..................................
106
6 Bug
111
7 App Store Submission 113
7.1 Distribution Alternatives..............................
113
7.2 Rejected.......................................
114
8 Conclusion 115
A Appendix 117
A.1 TSI..........................................
117
A.1.1 Our TSI...................................
117
A.1.2 Apple’s response..............................
118
Bibliography 119
v
1 Introduction
Smart-phones conquered the world in the past years and it seems like they have become
an indispensable tool for many people to alleviate their everyday life.By today they can
compete with the CPU power and memory of the personal computers built not even ten
years ago [37].Effective batteries allow to use the CPU power and performtasks like play-
ing music and videos or running a mobile internet connection for hours.Techniques like
UMTS and not at least the increasing coverage of WLAN access points provide mobile fast
internet connections and enable mobile client applications to communicate with servers
anywhere.Often a GPS unit in conjunction with a respective framework allows for local-
isation and navigation functionalities within applications.Cameras and 3D accelerometer
can serve as additional input interfaces.The smart-phones have proven to be a applicable
platform for many everyday life applications.One of the most advanced smart-phones is
being produced by Apple:the iPhone.By now there are hundreds of thousand iPhone ap-
plications available.More and more companies decide to take advantage of Apple‘s mobile
platform and develop their own iPhone applications in order to support their employees in
daily tasks (See [8] for examples).In this diploma thesis we want to analyse and evaluate
the paradigm of iPhone development.Therefore we will develop an iPhone application.
Along the procedure of development we want to get a feeling for all the aspects involved in
development.The iPhone comes with an outstanding multi touch screen as the main user
input interface.This is an important difference to usual computer input interfaces which
influences development heavily.The operating systemwas being designed to performwell
with limited resources and requires to adopt programming in terms of efficiency.Apple
provides a multiplicity of frameworks for development but also restricts developers and ap-
plications by certain policies and guidelines.In this diploma thesis we want to learn about
all these things.Our findings shall serve as a basic framework for further investigations
on developing business applications for Apple‘s mobile devices.By developing our own
iPhone application we want to get a feeling for the performance of the device and further-
more generate code which can be reused and investigated for future projects.In order to
achieve all this,we have addressed ourselves the task of developing an iPhone application
for the calculation of scholarly indexes.This idea seems to be an adequate challenge as it
will include parsing,processing and the storage of data.The key feature of our application
is to retrieve data from Google Scholar in order to calculate the h- and g-Indexes of schol-
ars.Hereby we want all necessary tasks,from data retrieval to index calculations,to be
performed on the device.The two indexes aimto be a measurement of the productivity and
1
1 Introduction
impact of the work of a scholar.They are both based on the amount of times the top most
cited publications are being cited of other publications.Before we present the technical
parts of the project we want to give a short introduction about the mentioned indexes,their
background and relevance.
1.1 The H-Index
The h-index was defined by J.E.Hirsch in his paper “An index to quantify an individual‘s
scientific research output” [42] in 2005 as the number of papers with citation numbers
>
=
h
.
For an illustration see figure 1.1 below.
Assuming a scholar
has published 22 pa-
pers.When we order
the papers based on
their citation counts,we
receive a table like the
one to the right.
The h-index is the num-
ber of the best cited
publications which have
been cited
h
times at
least.
For this example the
h-index therefore is 9 as
there are 9 publications
with at least 9 citations.
The 10th paper only
has 8 citations and thus
does not contribute to
the h-index in this case.
















































 
Figure 1.1
:
H-index calculation example
Hirsch claims the h-index to be a useful index to characterize the scientific output of a
researcher by combining quality with quantity and avoiding the disadvantages of the other
bibliometric indicators like the following:
2
1.1 The H-Index
1.
Total number of papers
(
N
p
)
:

Advantage:Measures productivity.

Disadvantage:Does not measure the impact of papers.
2.
Total number of citations
(
N
c,tot
)
:

Advantage:Measures total impact.

Disadvantage:Hard to find and may be inflated by a small amount of highly cited
papers which may not be representative for the individual if he/she is a co-author.
3.
Citations per paper
(
i.e.ratio of N
c,tot
to N
p
)
:

Advantage:Allows to compare scientists of different ages.

Disadvantage:Hard to find,rewards low productivity and disadvantages high
productivity.
4.
Number of “significant papers”,defined as the number of papers with
> y
citations:

Advantage:Eliminates the disadvantages of all criteria above,gives an idea of
broad and sustained impact.

Disadvantage:Randomly favours or disfavours individuals as
y
is arbitrary.Y
would have to be adjusted for different levels of seniority.
5.
Number of citations to each of the
q
most-cited papers:

Advantage:Overcomes many of the disadvantages of the criteria above.

Disadvantage:Not a single value and thus insufficient for comparison,
q
is arbi-
trary which again would favour or disfavours individuals randomly.
Although the h-index aims to measure the broad impact of an individual‘s work by respect-
ing quality as well as quantity,here are some aspects which have to be considered among
others.
1.
Different fields will have h values typically to the field.Thus the comparison of scien-
tists of different fields does not make much sense.
2.
The h-index is bounded by the total amount of publications.A scholar who published
five articles can only achieve an h-index of five even if these publications are highly
cited and would be the most significant articles in the whole field of research.
3.
The amount of co-authors of a paper in not being considered.
4.
Context is critical:
a)
Citations can be made in a negative context but still would contribute to a better
h-index
3
1 Introduction
b)
Many citations are used simply to flesh out a paper‘s introduction and thus have
no real significance to the work.
c)
Well-established researchers and projects are cited disproportionately more of-
ten than those less known.
5.
Manipulation possibilities:Systematic self citing can increase someone‘s h-index.
The same thing applies for indirect self citations which is the case when a co-author
self-cites a publication.One author could help another to increase his h-index by
citing publications which need few more citations to contribute to the h-index.
1.2 The G-Index
The g-index was introduced by Leo Egghe in his paper “Theory and practice of the g-index”
[39] in 2006 as an improvement to the h-index.The g-index is defined as the unique number
such that the
g
most cited articles received (together) at least
g
2
citations.Thus the g-index
inherits all the good properties of the h-index and in addition better takes into account the
top most cited articles.The h-index is robust in the sense that it is insensitive to lowly cited
papers as well as outstanding highly cited papers.Egghe claims latter to be a drawback
as the evolution of the most cited papers is not being taken into account.Once a paper
is selected to belong to the top
h
papers,the paper does not influence the calculation of
h-index in subsequent years even if it doubles its number of citations.Therefore Egghe
introduced the g-index to better take into account outstanding highly cited publications over
time.For an example see figure 1.2.
4
1.3 Acceptance of the indexes
Assuming a scholar
has published 22 pa-
pers.When we order
the papers based on
their citation counts,we
receive a table like the
one to the right.
The g-index is defined
as the number such that
the
g
most cited articles
together received at
least
g
2
citations
For this example the g
index therefore is 15 as
the 15 best cited papers
together have a citation
count of 230.But the 16
best cited papers do not
have a citation count of
256 or more.




















































































 








 
 


 
Figure 1.2
:
G-index calculation example
1.3 Acceptance of the indexes
The acceptance,especially of the h-index has increased in the years since its introduction
in 2005.The Wired Magazine published the article"The Genius Index:One Scientist’s
Crusade to Rewrite Reputation Rules"[40] in June 2009.The article states:"
In its nearly
four years of life,the relatively simple,flexible h-index has become the most talked-about
metric in the very hot science of rating scientists and their research,...Schools and labs use
such ratings to help them make grants,bestow tenure,award bonuses,and hire postdocs.
In fact,similar statistical approaches have become standard practice in Internet search
algorithms...
".Public lists of the h-indexes of scholars of specific fields [46] [47] further
suggest the broad acceptance of the h-index.Even though the g-index tries to eliminate
one of the weaknesses of the h-index [39],which even Hirsch acknowledged according
to the mentioned article in the Wired Magazine [40],it does not seem to have the same
popularity as the h-index yet.
5
1 Introduction
1.4 Google Scholar as the data source
In order to calculate the h- and g-index,our application needs a data source from which it
can retrieve the citation counts of the publications of the scholar of interest.Comprehen-
sive data sources are the “ISI Web of Science” [4],which is provided by Thomson Reuters,
Elsevier‘s “Scopus” [3] and Google‘s “Google Scholar” [1].There are several scientific pub-
lications which discuss and compare these sources,serving as data sources for calculating
h-indexes,intensively.The calculation results definitely vary by the data source being used
and there are different opinions,based on several criteria,on which data source serves best
for such calculations.We neither object to discuss the differences of these data sources
nor the topic of which data source serves best for the calculation of the indexes.
However,for a better understanding and an imagination of the impact of these differences
we will mention a few.
1.
The different sources have different coverage in different fields.[35]
2.
The coverage of non English publications differs [35]
3.
In contrast to WoS and Scopus,which index citations mainly from journal articles
and conference papers,citations found through GS come from many different types
of documents,including journal articles,conference papers,doctoral dissertations,
master’s theses,technical reports,research reports,chapters,and books,among
others [45]
4.
Google Scholar sometimes includes non-scholarly sources (e.g.,course reading lists),
phantom or false citations [45]
5.
Google‘s coverage of sources is not clear as they never published anything about it
6.
Google Scholar‘s processing is fully machine based and occasionally makes mis-
takes i.e.cannot adopt details like publication year,author,...or even double counts
citations [41]
7.
Web of Science and Scopus both administer data manually
Obviously those differences between the data sources have to be considered as they di-
rectly influence the h-indexes and their reliability.One may imagine that a particular source
results in higher h-indexes if it includes more sources than another.Again another might
provide lower h-indexes in a particular field.The h- and g-index on the other hand are quite
robust to minor data faults by their definitions and may compensate some of those aspects.
In her paper"Which h-index?– A comparison of WoS,Scopus and Google Scholar"[34]
Judit Bar-Ilan calculated and compared the h-indexes of highly cited Israeli researchers us-
ing the three mentioned data sources.In her conclusion she writes"
The findings show that
it matters which citation tool is used to compute the h-index of scientists
".Table 1.1 shows
6
1.4 Google Scholar as the data source
a selection of the h-indexes and the variations based on the data sources.
Researcher
Subject Area
WoS
Scopus
GS
Alexander,Gideon
Physics
32
30
20
Alon,Noga
Mathematics,Computer Science
14
17
27
Beeri,Catriel
Computer Science
3
3
8
Ciechanover,Aaron
Biology & Biochemistry
33
34
30
Dolev,Daniel
Computer Science
5
7
18
Mikenberg,Giora
Physics
31
10
4
Netzer,Hagai
Space Sciences
28
28
18
Oren,Moshe
Molecular Biology & Genetics
47
49
38
Peleg,David
Computer Science
8
11
21
Shainberg,Isaac
Ecology/Environment
8
10
9
Table 1.1
:
H-indexes according to Web of Science,Scopus and Google Scholar
Anne-Wil Harzing does not doubt that all these data sources have their own limitations but
also states in her publication"Google Scholar - a new data source for citation analysis"[41]
that she believes:"
In most cases,Google Scholar presents a more complete picture of an
academic’s impact than the Thomson ISI Web of Science
".Due to the fact that Google
Scholar is the only comprehensive data source which is available freely,we will use it as
the data source in our application.This also has the advantage that the results can be
reproduced by anyone.
7
1 Introduction
8
2 iPhone Development Introduction
During this diploma thesis we will often refer to technologies,methods and classes of dif-
ferent types.To make it easier for you to distinguish between custom code which we have
implemented or technologies already provided through Objective C or by the frameworks
we have used,we will mark methods,classes,frameworks and specific technologies in dif-
ferent colours.The
- DARK BLUE COLOUR -
shows that we are talking about something
specific to our application and usually means that we have implemented or created the
class or method or whatever we are talking about ourselves.The
- GENERAL TECHNOL-
OGY COLOUR -
stands for technologies,classes and methods provided either by one of
the frameworks we used or specific to Objective C.
When we started developing the current iPhone OS and SDK versions were 3.X.During
the development the new version of the previously called iPhone OS was introduced as
iOS (4.0).When the iOS came out,the new SDK version also was renamed in iOS SDK.
Even though we started developing in version 3.2,we switched to the new SDK when it
came out.However,in the following chapters we will refer to all versions of the iPhone - OS
and - SDK as iOS and iOS SDK.In cases where it is relevant,we will provide the specific
versions.Sometimes we talk about iPhone applications or apps.When we do so,we mean
iOS applications which run on the iPhone but also on the iPodTouch and possibly on the
iPad.
2.1 XCode,Interface Builder and the iOS SDK
Before you can start developing an iPhone application,it is necessary to install XCode
and the iOS SDK on your Mac.Your Mac has to be Intel-based and needs to run Snow
Leopard.The iOS SDK is not designed to run on other systems which makes the Mac
indispensable for serious development.XCode and the iOS SDK can be downloaded for
free after registering as an Apple developer,which is also for free.
9
2 iPhone Development Introduction
2.1.1 XCode
XCode is Apple’s IDE.It ships with built-in project templates,a graphical debugger,the
iPhone Simulator,Interface Builder and Instruments.
iPhone Simulator
The iPhone Simulator enables you to test your applications directly on your desktop without
connecting an actual device.
Interface Builder
Interface Builder is a tool for developing user interfaces graphically.It allows you to build a
complete user interface via drag and drop and then connect the individual components to
objects and methods in your code with so called
IBOutlets
and
IBActions
.
Instruments
Instruments provides a set of tools for inspecting memory usage,disk activity,network
activity,and graphic performance.Instruments is very helpful for tracking down memory
leaks and locating critical areas of memory usage.
2.1.2 iOS SDK
On top of the iOS Kernel there are four layers of services on which iOS applications can be
built.Figure 2.1 shows the layer hierarchy.
These layers provide different interfaces and technologies on different levels of abstraction.
The higher-level frameworks provide infrastructures for implementing standard system be-
haviour.Lower-level frameworks usually are suitable for implementing custom behaviour
which is not provided by higher levels.The starting point for building a new application
usually is the Cocoa Touch layer and the
UIKit
in particular.The frameworks at these layer
provide the fundamental infrastructure for an application whereat most technologies are
based on Objective-C.The UIKit framework provides the visual infrastructure for an ap-
plication,including classes for windows,views,controls and controllers for handling those
objects.
10
2.2 iPhone Limitations



 
 

Figure 2.1
:
iOS layers
Moving down from the Cocoa Touch layer to the next layer,the Media layer provides tech-
nologies to support drawing,audio and video.The interfaces on this layer are either
based on Objective-C or C.A C-based technology on this layer for example is OpenGL.
An Objective-C based technology on the other hand is Core Animation,which is a frame-
work for animating user interfaces.
The two lower-level layers,Core Services and Core OS contain the fundamental interfaces
for iOS.Most interfaces on this layer are C-based.A Core OS layer-specific technology for
example is the database technology SQLite.
2.2 iPhone Limitations
Developing for a mobile platform such as the iPhone,one has to consider several restric-
tions.Due to platformlimitations such as limited amount of memory and CPU power,there
is no garbage collection in iOS.This limitation directly affects development and is the reason
why the developer is responsible for retaining and releasing objects in memory.If an appli-
cation takes up too much memory,iOS simply forces it to quit.Applications running on iOS,
live in so called sandboxes,which is a security concept and restricts applications in terms of
data access.Applications only can access the data in their own sandbox.It is not possible
to access data from other applications or certain folders like the iTunes library.The lack of
physical input devices and the tiny screen might restrict user interaction to some extend.
On the other hand the iPhone offers technologies such as multi touch,an accelerometer
which detects device orientation and an on-screen keyboard.These technologies in com-
11
2 iPhone Development Introduction
bination with the provided frameworks such as the UIKit enable the developer to build rich
user interaction despite restrictions.
2.3 Objective-C and MVC
The iOS SDK is designed around supporting two programming paradigms.Object oriented
programming and the Model View Controller (MVC) design pattern.Objective-C is the
object oriented programming language which is used for the implementation of iOS appli-
cations.It is a superset of ANSI C that has been extended with certain syntactical and
semantic features derived from Smalltalk to support object oriented programming.Due to
the fact that Objective-C is based on a foundation of ANSI C,it is possible to mix straight
C with Objective-C.Inheritance becomes an important feature for hierarchically structuring
the behaviour of specific classes in the frameworks such as the UIKit framework.Many
classes provided by the frameworks,are shipped with the SDK,inherit from multiple par-
ent classes (Not multiple inheritance!).The
UIButton
for example inherits from the classes
UIControl
and
UIView
,thus acting as a
UIView
as well as a
UIControl
.The complete in-
heritance hierarchy of the
UIButton
class actually is
NSObject
:
NSResponder
:
UIView
:
UIControl
.If you want to built an application for iOS,you have to be familiar with Objective-
C.Apple’s document"Introduction to The Objective-C Programming Language"[25] is a
good starting point to learn Objective-C.
2.3.1 Memory Management
When you are programming an application for iOS,you will have to manually take care of
the memory management as there is no garbage collection available for iOS.This means
you have to manually allocate and free the memory which is allocated by your objects,as
soon as you do not need themany longer.If you do not take care of your memory properly,
your application will leak memory and you risk it to get terminated by the system at some
point.Therefore memory management is an important issue you have to deal with.In Co-
coa you will use a reference counting systemto take care of an object’s life cycle 2.1.When
you allocate an object it will have a reference count of one.You can manipulate the refer-
ence count by using the instance methods
retain
and
release
.If you retain an object the
reference will be incremented by one,if you release it,the reference count will be decre-
mented by one 2.2.As soon as the reference count is zero the object will be destroyed
automatically and the allocated memory freed.Another fundamental aspect is the object
ownership mechanismby which you can specify when to release an object.If you create or
retain an object,using one of the methods
alloc,new,copy
or
retain
,you own it.An object
thus can have multiple owners.If you own an object,you are responsible for releasing it
12
2.3 Objective-C and MVC
later.If you do not own an object on the other hand,you are not allowed to release it.So if
you release an object at some point in your code,you have to make sure that you are the
owner at this point.Of course the object can still have other owners.But you do not need
to care about existing other ownerships when you release an object.You simply have to re-
lease an object for each time you retained it and you release it as soon as you do not need
it any more.Apart from the release method you can send an
autorelease
message to an
object,to declare that you do not want to own the object beyond the scope in which you sent
the message.This means when you send an
autorelease
message to an object,its retain
count will automatically be decremented by one at some point in the future.Let’s assume
you create an object in a method to return it to the caller.In this case the method does not
want to take responsibility for the created object even though it has created it.Therefore
the method will call an
autorelease
message to the object before returning it.The caller
then has to make sure he acquires ownership for this object by sending a retain message
to it.Listing 2.6 is an example of latter.If the caller does not do so,it will be destroyed au-
tomatically at some point in the future.Maybe before the caller expects this.Some classes
provide so called
convenience constructors
,which return autoreleased objects.Method
names usually indicate if they retain objects by containing one of the words
alloc,new or
copy
in the method name.If they do not,the created object probably will get autoreleased.
Another fundamental concept you should be familiar with,are pointers.If you create an
object in Objective-C you assign it to a pointer.A reassignment of the pointer might cause
a memory leak as you loose track of the object originally assigned to your pointer.Listing
2.5 is an example of a pointer reassignment causing a memory leak.Moreover you need
to know that there are methods which retain objects (Compare listing 2.3 and 2.4).Other
methods in turn create autoreleased objects.Compare listing 2.7.Thus,you always have
to make sure whether the object will be autoreleased or if you are the owner and therefore
have to release it at some point.XCode integrates the tool
Instruments
which allows you
to scan for memory leaks.You can check for memory leaks by selecting Run –> Run with
Performance Tools –> Leaks in XCode.Another tip is to"build and analyse"your applica-
tion (Build –> Build and Analyze).XCode will then mark the lines of code which potentially
might cause memory leaks.
Listing 2.1
:
Object Lifecycle
1
NSString
*
hello = [[NSString alloc] initWithString:@
"
Hello
!
"
];
2
//
reference
count
is
1
3
[hello release];
4
/
*
5
calling
release
on
the
string
6
reference
count
is
0
7
object
will
be
destroyed
13
2 iPhone Development Introduction
8
and
memory
can
be
freed
9
*
/
Listing 2.2
:
Retain Message
1
NSString
*
hello = [[NSString alloc] initWithString@
"
Hello
!
"
];
2
//
reference
count
is
1
3
[hello retain];
4
//
reference
count
is
2
5
[hello release];
6
//
reference
count
is
1
7
[hello release];
8
//
reference
count
is
0
Listing 2.3
:
Some methods call retain on objects
1
NSNumber
*
number = [[NSNumber alloc] initWithInt:84];
2
//
number
reference
count
is
1
3
NSMutableArray
*
arr = [[NSMutableArray alloc]init];
4
//
arr
reference
count
is
1
5
[arr addObject:number];
6
/
*
7
addObject
calls
retain
on
number
!
8
number
reference
count
is
2
9
*
/
10
[number release];
11
//
number
reference
count
is
1
12
[arr release];
13
/
*
14
number
reference
count
is
0
15
arr
reference
count
is
0
16
*
/
Listing 2.4
:
Another example of a method calling retain on an object
1
UIView
*
viewX = [[UIView alloc]initWithFrame:CGRectMake(100,100,
100,100)];
2
//
viewX
reference
count
is
1
3
viewX.backgroundColor = [UIColor redColor];
4
[
self
.view addSubview:viewX];
5
/
*
6
addSubview
calls
retain
on
the
viewX
object
14
2.3 Objective-C and MVC
7
viewX
reference
count
is
2
8
*
/
9
[viewX release];
10
/
*
11
viewX
reference
count
is
1
12
will
be
0
when
the
parent
view
will
be
released
13
*
/
Listing 2.5
:
Reassignment of a pointer
1
NSNumber
*
number = [[NSNumber alloc] initWithInt:84];
2
//
original
number
(84)
object
reference
count
is
1
3
number = [[NSNumber alloc] initWithInt:85];
4
/
*
5
new
number
(85)
object
reference
count
is
1
6
reassignment
of
the
number
pointer
:
7
you
lost
the
pointer
to
the
original
number
object
8
and
therefore
caused
a
memory
leak
!
9
*
/
Listing 2.6
:
Autoreleasing
1
/
*
2
When
you
create
an
object
in
a
method
and
you
3
intend
to
return
it
,
you
have
to
autorelease
it
.
4
The
caller
on
the
other
hand
should
retain
it
if
necessary
5
*
/
6
- (NSString
*
)sayHello{
7
8
NSString
*
hello = [[NSString alloc] initWithString:@
"
Hello
!
"
];
9
return
[hello autorelease];
10
}
11
...
12
NSString
*
helloString = [
self
sayHello];
13
[helloString retain];
14
//
To
make
sure
the
object
will
be
kept
alive
15
...
16
[helloString release];
17
//
Call
release
when
you
do
not
need
it
any
more
15
2 iPhone Development Introduction
Listing 2.7
:
Autoreleasing
1
/
*
2
Some
methods
construct
autoreleased
objects
3
If
the
method
name
does
not
contain
alloc
,
new
or
copy
4
but
creates
an
object
,
it
probably
will
be
autoreleased
5
*
/
6
NSNumber
*
number = [NSNumber numberWithInt:84];
7
/
*
8
If
you
call
release
on
an
object
which
was
already
9
autoreleased
your
application
will
crash
10
*
/
2.3.2 MVC on the iPhone
Even though the iOS SDK is build around the MVC design pattern,the MVC pattern in iOS
does not always match the theory of the fundamental MVC pattern.
Views in an iPhone application are based on the class
UIView
.Nearly all user interface
classes are being derived from this class.Each iOS application usually contains one
UI-
Window
object,which is a special
UIView
object providing the root for all other
UIView
objects.A view can be displayed by adding it to the applications window object or by
adding it to another view by using the
addSubview:
method.A complete user interface can
be seen as a tree of sub views.In addition to the
UIView
objects,
UIViewController
objects
play a key role in managing views.Even though you can develop an application without
using any
UIViewController
class,in most cases you should not do that,as they have many
built-in functionality for managing user interfaces.They can provide so much behaviour
and functionality expected of an iPhone application that it would be a huge waste of time
to implement respective controller classes along the MVC architecture yourself.Especially
if you are new to iOS development,building an application without using view controllers,
simply is not an option you should consider at all.Viewcontrollers are responsible for laying
out the items on your screen and thus do not exclusively act as a controllers in the sense of
the MVC pattern.Usually one view controller is associated with one view object.This view
object usually contains a hierarchy of sub views whereat these sub views can be manipu-
lated by the view controller as well.View controllers take responsibility for rotating the view
depending on the device orientation and resizing views to fit in the boundaries defined by
special UI elements such as tool bars and navigation bars.The
UIViewControllers
classes
exist to make it easy to manage UI elements and build applications that conform to Apples
design guidelines.In addition to the base class
UIViewController
,there are special
UIView-
16
2.3 Objective-C and MVC
Controller
classes for special purposes.The
TableViewController
for example is a controller
specially designed for displaying data in the formof a table.The
UINavigationController
and
the
UITabBarController
both are controllers which are designed to navigate between other
view controllers.The navigation controller can be used to navigate between different levels
in a stack of view controllers.Similarly a tab bar controller can manage multiple distinct
view controllers allowing the users to switch between those by tapping the corresponding
tab.By combining different
UIViewController
classes,it is possible to build complex layouts.
Each view controller then manages a specific part of the layout or just takes responsibility
for switching between controllers.In our application for example,we combined a tab bar
controller with three navigation controllers whereat all three manage a stack of miscella-
neous view controllers.By now you might be able to imagine of how much functionality
you would relinquish if you would not use the provided
UIViewControllers
classes.It will
definitely be clear after you read the whole diploma thesis.The iOS SDK provides many
classes for implementing controllers and views,but it does not provide any model specific
templates.So it is up to you to implement callback methods and delegate protocols (See
2.3.3) to support the required functionality.
In the following,we will be talking a lot about view controllers,views and other classes
and objects.Thereby we sometimes use the class name even though we refer to an ob-
ject.Furthermore we will refer to controller objects of the class
UIViewController
as view
controllers.
UITableViewController
objects are being named table view controllers and so
on.Similarly we would refer to a custom controller object of the class
SuperSpecialCus-
tomViewController
as super special custom view controller.It might seem a bit confusing
now,but it should all be clear in the context.
2.3.3 Communication between objects
Controllers,models and views all are represented by objects designed to fulfil a specific
role in an application.Each of those objects contributes a limited set of behaviours to the
application.In order to get a task done,these objects might need to communicate with
each other at runtime.Therefore Cocoa provides several patterns by which objects can
talk to each other.The most important mechanisms in iOS are delegation,target-action
mechanism and notifications.
Delegation
Delegation is a way of handing over the responsibility for responding to some kind of event.
It is used by UIKit classes in order to hand over responsibility for responding to user inter-
action.A delegate object has to act in behalf of the object originally encountered the event.
17
2 iPhone Development Introduction
Therefore the delegating class holds a property usually called delegate.Furthermore it de-
clares a so called protocol.The protocol defines one or more methods the delegate object
has to implement.The delegating object itself does not implement these methods.A good
example is the
UITableView
class.It does not have a built-in way of responding to a tap on
a row.Instead it requires a delegate object which has to implement the delegate methods
such as
tableView:didSelectRowAtIndexPath:
which then implement the response to the
user interaction.Listing 2.8 shows an example of our application,where we use delegation
for the parser object to communicate with a view controller.The parser class defines the
ParserDelegate
protocol as illustrated by listing 2.8.Figure 2.2 illustrates the delegation
pattern in general.
Listing 2.8
:
Parser.h
1
//
Parser
.
h
2
3
@protocol
ParserDelegate
4
@required
5
- (
void
)requestHTMLFrom:(NSString
*
)url;
6
- (
void
)presentResults;
7
- (
void
)insertQuery;
8
- (
void
)setExpLastPage:(
int
)lastPage;
9
@end
10
11
@interface
Parser:NSObject {
12
id
<ParserDelegate> delegate;
13
...
14
}
15
16
@property
(nonatomic,assign)
id
<ParserDelegate> delegate;
17
...
18
2.3 Objective-C and MVC
 





 

 











Figure 2.2
:
Delegation pattern in general
The parser object holds a property to the delegate,in our case an instance of the
SearchView-
Controller
class.The search view controller conforms to the
ParserDelegate
protocol and
implements the required methods (
requestHTMLFrom:,presentResults,...
).In section
5.1.5 we will introduce the whole search flow.Hereby,the communication of the parser
object and the search view controller is an important aspect.For an illustration see figure
5.6 in the"Implementation"chapter.
Each iOSapplication has to implement at least one delegate,the application delegate which
adopts the
UIApplicationDelegate
protocol.This is crucial to any application as it must re-
spond to application-launch,application-quit,low-memory,and other messages from the
application object.
Almost identical to delegates there are data sources.Unlike being a delegate control of the
user interface,it is a delegate control of data.A data source is a reference held by
UIView
objects such as
UITableView
that require a data source from which they retrieve the data
they present on the screen.Most of the time,but not necessarily,that is the same object
as the delegate.Also similar to the delegate the data source must implement one or more
methods of a protocol to supply the view with the data to be displayed.In iOS applications,
the view controllers typically act as delegate as well as data source of their corresponding
views.This is another iOS variance of the MVC pattern as models are usually responsible
19
2 iPhone Development Introduction
for data encapsulation.Of course data source can be used in a model class either.
The Target-Action Mechanism
The target-actions mechanism is a lower-level way of redirecting user interactions.Espe-
cially controls like
UIButtons
use this mechanism to communicate specific user events to
other objects.In the UIKit,the children of the
UIControl
class almost exclusively define
most of the target-action mechanism for iOS.To set up a control to send an action mes-
sage to the target,you have to associate both,the target and action with a control event.
Listing 2.9 shows an example of the target-action mechanism with a
UIButton
.The button
(
subjectAreasBtn
) sets the target to self,the action to
@selector(displaySubjectAreas
) and
the control event to
UIControlEventTouchUpInside
.The target has to implement an appro-
priate respond in its selector.If it does not do that and the action-message is sent to the
target object anyway,the application will crash at runtime due to an undefined method call.
Listing 2.9
:
Target-Action Mechanism with UIButton
1
[subjectAreasBtn addTarget:
self
action:
@selector
(
displaySubjectAreas:) forControlEvents:
UIControlEventTouchUpInside];
An action message must have a unique signature.The method it invokes is of the type void
and has a single argument of the type id,named sender by convention.The sender iden-
tifies the control which sent the action message but is not really required to be specified.
Listing 2.10 shows the corresponding method which will be invoked.
Listing 2.10
:
Target-Action Mechanism - Method
1
- (
void
)displaySubjectAreas:(
id
)sender{
2
/
*
3
If
you
have
defined
the
(
id
)
sender
in
your
method
signature
4
you
can
then
access
it
within
your
method
5
i
.
e
.
to
make
decisions
based
on
the
senders
type
6
*
/
7
NSLog(@
"
%
@
"
,sender);
8
...
9
}
20
2.4 User Interface Design
Notifications
In addition to delegates and target-actions Cocoa offers another way of object communi-
cation.Notifications do not implement a tight coupling between the communicating ob-
jects and furthermore allow to broadcast notifications in contrast to delegation and action-
messages.With notification one object can inform multiple other objects about status
changes.Therefore the interested objects have to register with a notification center and
then start observing for notification messages.
2.4 User Interface Design
In section 2.1.1 we introduced Interface Builder and said that you can use it to build your
user interfaces graphically.In fact most project templates provided by XCode come with
a set of Interface Builder files and Apple suggests to build your user interfaces with it.On
the other hand it is not indispensable to use Interface Builder as you can create your user
interfaces programmatically in a view controllers
loadView
method.
2.4.1 More on Interface Builder
Interface Builder provides a library of user interface elements (See figure 2.3 ) and some
special objects,such as
UIViewController
objects,which you can add to your user interface
via drag and drop.See figure 2.4.
21
2 iPhone Development Introduction
Figure 2.3
:
Interface Builder Library - Elements you can add to your interfaces
22
2.4 User Interface Design
Figure 2.4
:
Interface Builder - Building UI via Drag and Drop
When you save a user interface created in Interface Builder,it creates a
XIB
file which
XCode automatically converts to a
NIB
file at build time so that it can be deployed with your
application.This means during development you will create and edit XIB files whereat your
application later will use NIB files.XIB files are XML based and provide some advantages
for development.NIB files on the other hand are archives.For further information check
out [6].When a NIB file is loaded into memory,the contained objects will be unarchived
and instantiated.Each NIB file contains one
File’s Owner
object which provides the link
23
2 iPhone Development Introduction
between your hand written code and the objects created from the NIB file.It is responsi-
ble for loading and managing the NIB file and the contained objects.Figure 2.5 illustrates
an example of our application.It shows the
AboutViewController.xib
main window with all
the objects contained in this XIB file.You can see the
File’s Owner
object is of the class
AboutViewController
.This means,when we create an instance of the
AboutViewController
class in our application,the about view controller’s NIB file and thus the contained user
interface will be loaded automatically.Because view controllers often have a corresponding
XIB file,XCode offers to create a corresponding XIB file when you subclass
UIViewCon-
troller
fromthe provided template.When you choose to do so,it automatically assigns your
controller class to the
File’s Owner
object in the XIB file.
Figure 2.5
:
AboutViewController as the
File’s Owner
object of the AboutViewController.xib
Often you need to access the user interface elements you have added to your XIB file
in your code.Or you want one of the buttons you have added to you user interface with
Interface Builder to trigger a method in your code.To connect the objects that you have
added to your XIB file and your code,there are
IBOutlets
and
IBActions
.
IBOutlets
With
IBOutlets
you can mark properties in your code simply by placing the
IBOutlets
key-
word in the property declaration.In the
SearchViewController
class for example,we have
defined the instance variable
*go
of the type
UIButton
to connect with a button in the XIB
24
2.4 User Interface Design
file.Therefore we added a property declaration and the
IBOutlets
.See listing 2.11.When
you then open Interface Builder,it looks for
IBOutlets
and allows you to connect the in-
stance variables in your code with objects in the XIB file of the same type.Your application
then can access and manipulate these objects during runtime.
Listing 2.11
:
Declaration of an IBOutlet
1
#
import
<UIKit/UIKit.h>
2
...
3
4
@interface
SearchViewController:UIViewController <
UITextFieldDelegate,ParserDelegate> {
5
...
6
UIButton
*
go;
7
...
8
}
9
...
10
@property
(nonatomic,retain) IBOutlet UIButton
*
go;
11
...
There are several ways how you can connect your
IBOutlets
with your code in Interface
Builder.It usually involves dragging something somewhere.In the Inspector window for
example,you can see the
IBOutlet
of an object.To connect your
IBOutlets
you can click
and drag themon the corresponding user interface elements of your XIB’s main window as
illustrated in figure 2.6.
Figure 2.6
:
Connecting an IBOutlet with the corresponding user interface element
25
2 iPhone Development Introduction
IBActions
IBActions
are methods in your code which can be triggered by objects,typically controls
loaded fromthe NIB file.Therefore you mark your methods with the return type
IBAction
to
tell Interface Builder to treat it like a target action.See target-action mechanism in section
2.3.3.Usually the method takes one argument
sender
of the type
id
which is a reference to
the object sending the action message.The return type
IBAction
is the same as void.If you
have an
UIButton
in your user interface which you have created in Interface Builder,you
can connect its
UIControlEventTouchUpInside
event with an
IBAction
defined in your view
controller’s code.In our
AboutViewController
class we have defined three methods.To
connect these with controls of the corresponding XIB file,we marked these with the return
type
IBAction
as illustrated in listing 2.12.The connection of
IBActions
with corresponding
methods works similar to the connection of
IBOutlets
with user interface elements.When
you select your target object and open the Inspector window in Interface Builder you can
see the
IBActions
you have defined in your code.Again you can click and drag them onto
a control in your XIB file.When you do so,Interface Builder will list all events of the control.
You can then choose to connect an event with your
IBAction
.See figure 2.7.
Listing 2.12
:
Declaration of IBActions in code
1
#
import
<UIKit/UIKit.h>
2
...
3
4
@interface
AboutViewController:UIViewController <
MFMailComposeViewControllerDelegate> {
5
6
}
7
8
- (IBAction)presentInstrcutionsVC;
9
- (IBAction)emailUs;
10
- (IBAction)visitDBISWebsite;
11
...
Buttons in general usually are being connected to the methods they trigger either program-
matically (See target-action mechanism in section 2.3.3) or through a connection to an
IBAction
in their XIB file.Note that neither Interface Builder nor XCode will warn you about
non-connected
IBOutlets
and
IBActions
.So if you forget to make a connection your appli-
cation will probably crash at some point or just not behave like you expect it to.Also be
careful,when you rename
IBActions
or
IBOutlets
,you have to reconnect them in Interface
26
2.4 User Interface Design
Figure 2.7
:
Connecting an IBAction with a control of your XIB
Builder.Otherwise you will cause an error too.
Interface Builder primarily simplifies building user interfaces and saves writing code.It is
important to know that the entire file and referenced frameworks or code must be loaded
into memory so that individual objects can be instantiated.Therefore it is important to keep
NIB files small in order to keep memory usage low.
2.4.2 Coding user interfaces vs.Interface Builder
You do not have to use Interface Builder to build your user interfaces.If you decide not to
use Interface Builder you will have to write the corresponding code yourself.Depending on
the complexity of your user interface this can be quite a lot.Laying out user interfaces and
setting all the necessary attributes requires to write several lines of code.The
loadView
method of your controller is where you would put this code.Listing 2.13 shows an exam-
ple where we simply added an
UILabel
and an
UIButton
to a
UIView
in an view controller.
Figure 2.8 shows the resulting user interface.In comparison if you would take advantage
of Interface Builder instead,you would not have to write a single line of code and still could
adjust your user interface objects programmatically in the
viewDidLoad
method of the view
controller.However,there are lively discussions on the internet about NIB files slowing
down performance as they are expensive to load.We did not make any experience with
NIB files slowing down performance significantly in our application.But it also is not subject
of this diploma thesis to compare the performance of the different methodologies of loading
27
2 iPhone Development Introduction
user interfaces.On the other hand one might imagine that thoughtlessly assembling all
user interfaces in a single XIB file might slow down performance as all elements are being
loaded in memory at once.
Listing 2.13
:
Coding user interfaces
1
#
import
"
HandMadeViewController
.
h
"
2
3
@implementation
HandMadeViewController
4
5
- (
void
)loadView {
6
7
//
Implement
loadView
to
create
a
view
hierarchy
programmatically
,
without
using
a
NIB
.
8
9
CGRect rectFrame = [UIScreen mainScreen].applicationFrame;
10
UIView
*
view = [[UIView alloc] initWithFrame:rectFrame];
11
view.backgroundColor = [UIColor grayColor];
12
self
.view = view;
13
14
UIButton
*
button = [UIButton buttonWithType:
UIButtonTypeRoundedRect];
15
[button setTitle:@
"
A
Button
"
forState:UIControlStateNormal
];
16
button.frame = CGRectMake(80,210,160,40);
17
[
self
.view addSubview:button];
18
[button release];
19
20
21
UILabel
*
label = [[UILabel alloc]initWithFrame:CGRectMake
(60,300,200,100)];
22
label.text = @
"
This
is
a
label
...
"
;
23
label.backgroundColor = [UIColor grayColor];
24
label.textAlignment = UITextAlignmentCenter;
25
label.textColor = [UIColor blackColor];
26
label.font = [UIFont systemFontOfSize:20];
27
[
self
.view addSubview:label];
28
[label release];
29
30
}
28
2.4 User Interface Design
Figure 2.8
:
The user interface generated by the code of listing 2.13
On the following pages we will refer to navigation bars and tool bars.Just that you know
what we are talking about,in the interfaces of view controllers the navigation bar (
UINavi-
gationBar
) always is on top whereas the tool bar (
UIToolbar
) is located at the bottomof the
interface.For an illustration see figure 2.9 below.
2.4.3 Human Interface Guidelines
Before you start developing an application you should have a look at Apple’s
Human Inter-
face Guidelines
[33].The documents basically describe how you should design your user
interfaces to achieve a rich user experience in your application.iOS and the frameworks
with which you will implement your application provide several standard techniques how
to implement user interaction.When you are building an application for iOS you should
not forget that you are designing for a multi touch screen and respective user interfaces
and interactions will have to be different to what you are used to from desktop applica-
tions.Moreover iOS users expect a consistent behaviour not only application wide,but
also across iOS applications.This has the advantage that users are able to operate any
iOS application quickly.Apple provides several techniques and principles to support you in
designing user interfaces.Animating your user interactions and interfaces can be crucial in
order to achieve rich usability.You also should be aware of the fact that violating Apple’s
Human Interface Guidelines might be a reason for your application not to be accepted for
29
2 iPhone Development Introduction
Figure 2.9
:
Navigation Bar and Tool Bar
the distribution in the App Store.But we will talk about the
Review Guidelines
in the next
section.
2.5 Review Guidelines
If you are developing an iPhone application,you may want to offer it in the App Store where
you can find hundreds of thousands apps by today.You need to know that not every app
actually makes it into the App Store.Apple reviews each app which is being submitted for
distribution.There are quite a few restrictions,not only in terms of how you have to build
and design your app,but also in terms of the content and the functionality it provides.In
the
Review Guidelines
and the
iOS SDK Agreement
,which you have to agree to in order to
use the iOS SDK,you can find what is allowed and what is not.These terms also apply to
third party libraries which you have included in your project.So be careful with third party
libraries as they can cause your app to get rejected.In order to read the Apple’s Review
Guidelines,you need to register as a developer.The guideline’s introduction states:"...We
don’t need any more Fart apps.If your app doesn’t do something useful or provide some
formof lasting entertainment,it may not be accepted....We will reject Apps for any content
or behavior that we believe is over the line.What line,you ask?Well,as a Supreme Court
Justice once said,"I’ll know it when I see it".And we think that you will also know it when
30
2.6 Test your app on the device
you cross it.To give you some sense of what might cause an app to be rejected we have
listed a few restrictions of the current Review Guidelines below.

Apps that crash will be rejected

Apps that use non-public APIs will be rejected

Apps that download code in any way or form will be rejected

Apps that are"beta","demo","trial",or"test"versions will be rejected

Apps that duplicate apps already in the App Store may be rejected,particularly if
there are many of them

Apps that are not very useful or do not provide any lasting entertainment value may
be rejected

Apps that do not notify and obtain user consent before collecting,transmitting,or
using location data will be rejected

Apps that are primarily marketing materials or advertisements will be rejected

Apps must comply with all terms and conditions explained in the Apple iPhone Human
Interface Guidelines and the Apple iPad Human Interface Guidelines

Apps that do not use systemprovided items,such as buttons and icons,correctly and
as described in the Apple iPhone Human Interface Guidelines and the Apple iPad
Human Interface Guidelines may be rejected

Apps containing pornographic material,defined by Webster’s Dictionary as"explicit
descriptions or displays of sexual organs or activities intended to stimulate erotic
rather than aesthetic or emotional feelings",will be rejected

Apps containing references or commentary about a religious,cultural or ethnic group
that are defamatory,offensive,mean-spirited or likely to expose the targeted group to
harm or violence will be rejected

Apps that include the ability to make donations to recognized charitable organizations
must be free
As we said,these are just some of the restrictions,there are many more.We even made
an experience with the restrictions ourselves as we knowingly used a non-public API in our
application and tried to submit it for distribution (See 7.2).
2.6 Test your app on the device
At the beginning of this chapter we told you about the iPhone Simulator 2.1.1.The simula-
tor is great because it allows you to investigate iPhone development without actually having
31
2 iPhone Development Introduction
a device.It also is practical during development for testing and debugging features quickly.
But if you are serious about developing an app for the distribution in the App Store,you
have to get a device.The cheapest option is the iPod Touch as the primarily difference to
the iPhone is that it does not support the mobile communication technologies.For many
apps,an iPod Touch will be sufficient for testing,for others it won’t.That depends on the
functionality you are planning to develop.However a real device is indispensable when it
comes to testing your app.You can get the real"look and feel"of your application only on
the device.Even more important you have to make sure the app in general performs well
on the device.This is not assured as the simulator in some cases behaves differently to
the device.Unfortunately the device is not the only thing necessary for testing.You also
have to be enrolled in one of the iOS developer programs.If you are studying or teach-
ing at a university you might have the possibility to enrol for the
iOS Developer University
Program
.It is free and allows you to test your apps on iPads,iPhones,and iPods.It does
not allow to distribute your apps in the App Store though.If you are planning to do so,
you will have to enrol in one of two programs,either into the
Standard Individual Program
or the
Standard Company Program
.Either one will cost you a fee of $99 USD per year.
For more information about the developer programs check out Apple’s Support Center [11].
When you have a device and you are enrolled in one of the developer programs,there are
still some steps required before you finally can execute your code on your device.When
you log into the iOS Development Center with your developer account,you will find many
resources about the required steps for testing and app on a device.Many developers on
the internet complain about having problems with setting up the device for testing.In order
to run your application on a device you need to sign it with a valid signing identity.To sign
your application for development you need a private key,iPhone Developer Certificate,and
a Development Provisioning Profile.The private key is necessary so that XCode can sign
your app binaries.The Developer Certificate is a electronic document that associates your
digital identity with information including your name,email address,or business.Provision-
ing profiles let XCode know which certificate/private key pair to use to sign your application
and let the device know how to verify the applications installed on them.When you are
signed in at the iOS Developer Center and you go to the
Provisioning Portal
,click on
Cer-
tificates
and then select the
How To
tab [31],you will find the required steps for setting up
your device for testing.As you will see there it is also possible to transfer your private key
to other Macs,so that you can work from multiple systems.We actually did this once and
can confirm that it worked for us.But before you can install your application,you have to
register your device for development.Therefore you can go back to the"
Home
"area of the
Provisioning Portal,launch the provisioning assistant and follow along the steps.Another
option is to open your
Organizer
in XCode (
Window –> Organizer
).If you have connected
a device,it should automatically appear in the
Devices
section.When you right click and
choose"
Add device for development
"the provisioning profile should be generated and au-
tomatically installed on your device.If everything is set up the device should be marked with
32
2.6 Test your app on the device
a green button and you should be able to see a provisioning profile named
TeamProvision-
ing Profile
for your device.Furthermore you should be able to see your provisioning profile
matching your certificate in your applications info.plist file in the
Build
Tab under the
Code
Signing Identity
section.You can find the info.plist file in XCode under targets,it is named
like your application.Just leave the selection to automatic selection and you should be able
to run your application on the device by selecting
Device
from the big button on the top left
in XCode before you hit
Build and Run
.An issue which you still could stumble across is if
you do not have the right version of iOS on your device.Also you might have to change
your bundle identifier.The bundle identifier is a unique identifier for your application.In my
experience this should not cause any problems during the development phase.But if you
get such an error you should know the bundle identifier can be specified in the
Properties
tab of your info.plist file.By convention the bundle ID should be named something like
com.companyName.appName (top-level Internet domain.companyName.appName)
and is
being defined based on the AppID you are using for provisioning.If you experience any
kind of problem you should be able to solve them by reading the respective documents in
the provisioning portal carefully.
33
2 iPhone Development Introduction
34
3 Requirements
In this chapter we describe all the requirements we determined for our application.We
defined most of the requirements before we started with developing of course.However,
some functionality and thus requirements emerged during the process of implementation.
3.1 Requirements defined before implementation
3.1.1 Calculation of h- and g-indexes
The key functionality of our application is the calculation of h- and g-indexes based on the
data we retrieve fromGoogle Scholar.In the following,we sometimes will refer to these two
indexes as scholarly indexes.
3.1.2 Manage search results
Display the calculated indexes and the publications which the results are based on
After the calculation we need to display the results in a comprehensible way.The user
needs to be able to check the publication his or her results are based on.
Function to edit results by deleting and restoring publications
Search results can contain publications from not requested authors,i.e.when he has the
same name as the requested author.Therefore the user must be able to manually edit
his/her results by deleting,merging and restoring publications.This means when one publi-
cation is being deleted,the results have to be recalculated,because the deleted publication
does not contribute to the indexes any longer.Restoring must behave conversely.Merging
is being explained in section 3.1.3 below.
35
3 Requirements
Manage stored search results:save,display and delete
We need functionality for managing search results.The search results not only contain
the indexes but all publications the indexes are based on.We want to be able to store
and delete the indexes and edit the corresponding set of publications at any time.Again
editing the set of publications refers to selecting,deselecting and merging publications for
the calculations of the results.
Functionality to email the results
The application should have functionality to email those results in the form of a pdf docu-
ment.
3.1.3 Merging publications
Google Scholar sometimes delivers the very same publication as two or even more different
publications,i.e.due to variations in the title or the same title but different publication types
or versions.This might distort the results.A functionality which allows to merge multiple
publications and hence their citation counts is required to fix this issue.
3.2 Requirements emerged during the implementation
process
3.2.1 Graph Feature
For an author of a publication it might be interesting to see howhis publications are evolving
over time.Therefore we conducted to implement a graph feature as it is possible to retrieve
citation counts per year.
Functionality to email the graph
It would be nice to be able to email the evolution graph as a pdf or image.
36
3.2 Requirements emerged during the implementation process
3.2.2 Comparison Feature
The scholarly indexes provide some kind of measurement of the success and impact of an
author.But the indexes are not very useful until they are mapped to some kind of scale.
Thus it would be useful to compare someone’s results with others of the same area of
research.For comparison,we thought it would be best to display two results in the same
hierarchical context.This feature also allows to analyse changes or even the evolution of a
scholarly index as it is possible to limit search requests to specific time intervals.Another
option is to submit a search,save the results and submit the exact same search at some
point in the future again.If you then compare the results of both,you can see if the indexes
increased or not.You will even see if the citation counts of specific publications increased.
3.2.3 Remember Feature
If you request the same search once in a while,maybe to check if there are new citations
which effect the indexes,you would have to edit the search results each time.Therefore a
feature would be nice which can handle the editing of the search results for you based on
the latest previously submitted search and the corresponding undertaken editing.
37
3 Requirements
38
4 Architecture
4.1 Controller Hierarchy
Chapter 3 describes the different features that we initially defined for our application.Be-
fore we could start developing we had to discuss how to structure these features in our
application.As a result we identified two main functionalities which should be accessible
right away,the calculation of the two indexes as the key feature and some kind of a results
manager.Furthermore we would have to include instructions and information about the
application which eventually resulted in three dividable parts.With that in mind,we could
think about how to realize this in our application and found the
UITabBarController
suitable
for sectioning our functionalities.
4.1.1 UITabBarController Class
The
UITabBarController
class is a template for a special controller.A controller for switch-
ing between other view controllers.In the
UITabBarController
class reference [5] Apple
says that this class is not intended for sub-classing.Instead you should use instances of
it as-is to present an interface that allows the user to choose between different modes of
operation.A tab bar at the bottom of the controller’s interface allows to select one of the
provided modes.Each tab is associated with a specific view controller.When the user
selects a tab,the tab bar controller presents the root view of the corresponding view con-
troller.All previous views are being replaced,even if the tab was previously selected.With
the
selectedViewController
property you can choose the controller which is being displayed
initially.By conforming to the
UITabBarControllerDelegate
,objects can be notified about
the interactions of the tab bar controller.
XCode provides a tab bar application template.It was the starting point for our application.
It includes three XIB files of which the
MainWindow.xib
was the important one to us.It
contains a tab bar controller serving as the root controller of our application.The template
automatically adds the view of the tab bar to the application’s window.We removed all
useless parts like the two other XIB files and the
FirstViewController
object.In Interface
Builder we added three controllers of the type
UINavigationController
(Compare section
39
4 Architecture
4.1.2) to the tab bar controller,each one serving as the root controller of one tab.All four
controllers are being instantiated from the
NIB
file,not requiring us to write a single line of
code.Each navigation controller in turn,holds a custom root view controller.In our appli-
cation these are controllers of the types
SearchViewController
,
HistoryTableViewController
and the
AboutViewController
as you can see in figure 4.1.Figure 4.2 further illustrates that
each of the mentioned controller manages a specific part of the user interface.

  



  



  
  

  
 
 

  
  

  



  
Figure 4.1
:
UITabBarController with one UINavigationController per tab
4.1.2 UINavigationController Class
Similar to the
UITabBarController
class the
UINavigationController
class implements a spe-
cial view controller for switching between other view controllers.Again (Compare section
4.1.1 ) you are not supposed to subclass it but use unmodified instances of it for presenting
a hierarchical user interface.A navigation controller therefore keeps track of the hierarchy in
a navigation stack and provides a back button for moving back in the navigation hierarchy.
To modify the stack,and therefore navigate in your application,the navigation controller
provides two methods,
pushViewController:animated:
and
popViewControllerAnimated:
.
When you push your custom view controller on the stack,its view will be displayed and
the navigation controls will be updated.The
popViewControllerAnimated:
method is used
to navigate back in the hierarchy.This functionality usually is provided by the back button
in the navigation bar of the navigation controller.The navigation controller provides the
UINavigationControllerDelegate
protocol to notify other objects about its navigation.
Figure 4.3,4.4 and 4.5 show the complete navigation structure of the three navigation con-
trollers managed by the tab bar controller.The three figures represent the entire navigation
40
4.1 Controller Hierarchy
Figure 4.2
:
The user interface managed by multiple controllers
flow of the application.There are of course other controllers and classes.But all controllers
which are part of the navigation tree have corresponding graphical user interfaces which
they present at the respective points of the application flow.


 



 


 


 


 


 







Figure 4.5
:
Navigation-tree of the UINavigationController of the right tab
41
4 Architecture


 
 

 
 

 
 

 



 


 


 


 


 



 



 
 !" 
 

#
$
%
&
'
(
)
*
+
,
-
Figure 4.3
:
Navigation-tree of the UINavigationController of the left tab
42
4.1 Controller Hierarchy






 


  

 

  




  

 

 

 

 

 


!" # 

$
%
&
'
(
)
*
+
,
-
.


Figure 4.4
:
Navigation-tree of the UINavigationController of the tab in the middle
43
4 Architecture
4.1.3 Customcontrollers loaded through the MainWindow NIB
Our
MainWindow.xib
file contains a controller of the class
HistoryTableViewController
.It
inherits from the class
UITableViewController
,which is a special controller for presenting
data in the formof a table.It does not have a corresponding XIB file as the user interface is
loaded programmatically.We will talk about the
UITableViewController
class in detail later.
The
SearchViewController
class as well as the
AboutViewController
class both have their
own XIB files which contain the corresponding user interfaces.
4.2 CustomController Inheritance
All controllers in our application inherit from the
UIViewController
class provided by the
UIKit framework.Because the custom controllers of our application share properties and
functionalities it makes sense to structure them into an inheritance-hierarchy like the con-
trollers of the UIKit framework (Compare section 2.3).Therefore code can be reused and
is easier to maintain.Figure 4.6 illustrates the following explanation.
4.2.1 UIKit Controllers
The yellow controllers of the types
UIViewController
and
UITableViewController
both are
included in the UIKit framework.All controllers inherit from the class
UIViewController
.
4.2.2 Super Controllers
The red controllers are custom controllers providing different levels of functionality which
other controllers may implement through inheritance.
BasicViewController
The
BasicViewController
class includes a reference to the database controller and an id to
the database entry it manages.Furthermore it provides two basic methods.One to get the
current year and another to display an alert message to the user.
44
4.2 Custom Controller Inheritance

 
   

  
 
  
   

   
 
   
   

 
 
   

  

   


!  
  
" #  
" #$ # 
 
"   
  

# 
  
 
 
 
 
% &  


#  
 
##  '&
Figure 4.6
:
Custom Controller Inheritance Hierarchy
45
4 Architecture
BasicTableViewController
The
BasicTableViewController
class only provides a reference to the database controller
and an id to the database entry it manages.It inherits fromthe class
UITableViewController
and therefore primarily is for displaying data in the form of a table.
IntermediateViewController
The
IntermediateViewController
class extends the functionality of the
BasicViewController
class by two methods for the calculations of the two scholarly indexes and further references
for holding a set of database entries and the two indexes.Additionally it provides a special
view for communicating that it is busy.
ResultsViewController
The
ResultsViewController
class extends the functionality of the
IntermediateViewCon-
troller
class by a several properties and methods,all to display and manage results.Another
characteristic is the ability to send email.
4.2.3 CustomControllers
The green controllers are customviewcontrollers which inherit their basic functionality from
one of the provided controller classes and extend their functionality in order to fulfil specific
tasks.These controllers actually get instantiated in code.
4.3 Parsing and Database Functionality
4.3.1 Parsing
All parsing functionality is being encapsulated by the
Parser
class.The only controller
object which needs to communicate with the parser object is the
SearchViewController
object as it serves the data to be parsed.The communication between both objects is
being implemented through delegation (Compare section 2.3.3).The parser object also has
a reference to a
SQLiteController
object which is instantiate by the search view controller
and only passed on to the parser object when it is being created.More on this in the next
section 4.3.2.For a visualization see figure 4.7.
46
4.3 Parsing and Database Functionality


 
 


 
 

 
 

 
 
 

 

 
  

 

 
  

 
Figure 4.7
:
Database Access
4.3.2 Database Access
There are two controllers which actually instantiate a
SQLiteController
object in order to
access the database:the search view controller and a controller of the class
HistoryTable-
ViewController
.Both controllers then pass on their reference to other objects when these
are being created and require database functionality.See figure 4.7.None of our con-
trollers belonging to the third tab of our tab bar controller needs to access the database.
Alternative data persistence technologies are being discussed in section 5.2.6.Section
5.2.7 explains the integration of the SQLite library.
In our database we want to store the results of a search.Therefore we store the search
parameters in a table called
queries
.In order to store the publications of a search we create
a new
results
table for each time the user submits a search.The relation between query
47
4 Architecture
and results table is based on the auto incremented ID field of the query entries,simply
by naming a corresponding results table
results_queryID
.Figure 4.8 illustrates the binding
between the query entries and the results tables.Figure 4.9 and 4.10 show all fields of the
corresponding tables.











































































Figure 4.8
:
Table relations
48
4.3 Parsing and Database Functionality
Figure 4.9
:
Queries table structure
Figure 4.10
:
Results table structure
4.3.3 Outsourcing parsing to a server
As an alternative to parsing the data on the device,we could parse it on a webserver.Of
course a server could parse data much faster than our mobile devices and implement a
central caching mechanismso that data would be available rapidly.The described scenario
typically would be implemented using a webservice architecture.Our application,as the
webservice client,would have to implement functionality for consuming the webservice
provided by the server.Unfortunately the iOS SDK does not provide a special framework
for consuming webservices and we would have to implement this functionality ourselves
using a compatible XML parser.There are other reasons why we did not choose to use a
49
4 Architecture
webservice for data processing.The first and most crucial reason is that we wanted to learn
about the software and hardware potentials of the device and thus constituted to perform
all tasks on the device right fromthe start (See chapter 1).Secondly we would have had to
face the problem of concealing the identity of the server because Google Scholar restricts
the amount of requests in a certain amount of time based on the IP address.Depending on
howmany users would try to use the application,and thus the webservice,our server would
get blocked quickly without respective"concealing"technique.There might be solutions to
the challenge of building such a"concealing"mechanism.But on the other hand it would