430
Σύνολο Προβολών
430
Προβολές στο TechyLib
0
Προβολές από Ενσωμάτωση
0
Αγαπημένα
2
Downloads
Αφότου κάνετε την επιλογή σας, κάντε αντιγραφή και επικόλληση τον κώδικα ενσωμάτωσης που θα εμφανιστεί.
1
SERIOUS
ABOUT
SOFTWARE
iOS
App
Development
Juha-‐Ma5
Liukkonen
Mar
22,
2011
Contents
•
IntroducCon
to
the
iOS
PlaEorm
•
iOS
Concepts
for
SW
Designers
•
App
Elements
•
CreaCng
and
Deploying
an
App,
step-‐by-‐step
•
Advanced
programming
topics
•
DistribuCng
your
App
Extensive
documentaCon
available
at:
hNp://developer.apple.com
2
Bonus
sector:
brief
introducCon
to
Windows
Phone
7.
3
IntroducCon
to
iOS
iOS
Basics
•
iOS
is
a
low-‐footprint
adaptaCon
of
Apple’s
Mac
OS
X
•
Mach
microkernel
•
BSD
unix
derived
libraries
and
userland
•
ObjecCve
C
runCme
•
Used
in
iPod
Touch,
iPhone
,
iPad
,
Apple
TV
•
Touch
based
user
interface
•
RevoluConized
the
industry
in
2007
•
Mac’s
AppKit
replaced
with
touch-‐centric
UIKit
layer
•
Unix
layers
below
the
proprietary
UIKit
are
mostly
open
source
•
So^ware
developed
using
ObjecCve
C/C++
•
IniCally
Apple
aNempted
only
Web
apps,
but
that
didn’t
work…
•
Code
runs
naCve,
effecCve
use
of
hardware
resources
4
iOS
Architecture
5
The
Core
OS
is
shared
with
the
full
Mac
OS.
Core
Services
is
a
subset
of
full
Mac
OS.
Apps
are
wriNen
to
use
Cocoa
Touch
(
UIKit
)
and
Media
services
layers.
The
full
Mac
OS
X
has
a
wide
array
of
features,
as
can
be
expected
from
a
desktop
OS.
There
are
three
different
app
frameworks,
for
apps
based
on
three
different
technologies.
iOS
APIs
and
compaCbility
•
Apple
has
a
strict
2-‐major-‐versions
policy
•
Older
so^ware
versions
are
deprecated
quickly
•
So^ware
upgrades
are
free
and
easy
to
do
-‐>
most
users
run
the
latest
version
•
Currently
iOS
3
and
4
supported
•
Only
the
oldest
devices
(
iPhone
,
iPod
Touch
1
st
gen)
stuck
with
iOS
3
•
iOS
2
introduced
the
App
Store
(
iOS
1
was
Web
apps
only)
•
iOS
3
is
single-‐tasking,
but
introduced
lots
of
new
(even
basic)
features
•
iOS
4
=
current
version
•
MulC-‐tasking
–
having
mulCple
apps
in
memory
simultaneously
•
FaceTime
videoconferencing
•
iBooks
,
iAd
,
user
interface
tweaks
6
iOS
variance
•
Android
suffers
from
device
variance…
iOS
is
not
immune,
either
7
iPod
Touch
iPhone
3GS
iPhone
4
iPad
iPad
2
CPU
800 MHz
armv7
600 MHz
armv7
1 GHz
armv7
1 GHz
armv7
2x1 GHz
armv7
RAM
256 MB
256 MB
512 MB
256 MB
512 MB
Screen
960x640
480x320
960x640
1024x768
1024x768
Cameras
0.7 MP +
VGA front
3.2 MP
5 MP +
VGA front
-
0.7 MP +
VGA front
Sensors
Gyro
Compass,
Accel
Compass,
Accel
,
Gyro
Compass,
Accel
Compass,
Accel
,
Gyro
GPS
-
Yes
Yes
In 3G
models
In 3G
models
Note: only models currently in production.
iOS
UI
basics
8
The
App-‐centric
user
interface
is
iconic.
No
widgets
or
distracCons,
just
a
quick
launch
shortcut
bar
at
the
boNom,
and
one
hardware
buNon
to
press
for
home.
User
interface
elements
are
large
and
easy
to
use
with
a
finger.
Text
input
is
performed
with
an
on-‐screen
virtual
keyboard.
9
iOS
Concepts
for
SW
Designers
App
model
for
mobile
world
•
ApplicaCon
model
inherited
from
Mac
OS
X
•
TradiConal
C
main()
to
instanCate
UI
event
loop
•
Strict
Model-‐View-‐Controller
hierarchy
•
Data
Model
objects
manage
data
content
•
View
Controller
objects
perform
view
setup
and
most
reacCve
acCons
•
View
objects
manage
on-‐screen
objects
•
“Quick
launch,
short
use”
•
UI
and
the
event
loop
are
set
up
as
first
things
(generated
code)
•
Usually
View
Controller
unserializes
views
from
a
.nib
file
(generated
XML)
•
All
code
is
naCve
•
ObjecCve
C/C++,
preference
to
avoid
garbage
collecCon
10
Key for mobile app: save power.
Do work only when you have to.
ObjecCve
C/C++
•
A
cross
between
Smalltalk
and
C/C++
•
Some
say,
“object
oriented
C
done
right”
•
SyntacCcally
quite
different
from
C++,
conceptually
not
so
much
•
Significant
use
of
pre-‐processor
direcCves
•
Allows
for
run-‐Cme
binding
of
objects
•
Apple’s
FoundaCon
and
toolkit
libraries
rely
heavily
on
ObjecCve
C
features
•
Original
design
from
NextStep
circa
1982
•
Evolved
into
current
Mac
OS
X
circa
1998
•
Proven,
flexible
and
very
performant
architecture
11
ObjecCve
C/C++
sample
12
@implementation
MyClass
- (
id)initWithString:(NSString
*)
aName
{
self = [super init];
if (self) {
name = [
aName
copy];
}
return self;
}
+ (
MyClass
*)
createMyClassWithString
: (
NSString
*)
aName
{
return [[[self
alloc
]
initWithString:aName
]
autorelease
];
}
@end
id
MyClass::initWithString(NSString
*
aName
)
{
this = ::init();
if (this) {
name =
aName
->copy();
}
return this;
}
static
MyClass
*
MyClass::createMyClassWithString(NSString
*
aName
)
{
return (new
MyClass
())->
initWithString(aName
));
}
Objective-C implements
reference counting and
garbage collection via
the
autoreleasepool
.
The
Model-‐View-‐Controller
paNern
•
Strict
separaCon
of
concerns
•
Model
–
data
•
View
–
display
•
Controller
–
mediates
between
the
two,
understanding
applicaCon
state
13
The
Delegate
paNern
•
Delegate
objects
handle
app-‐specific
logic
•
In
C++
or
Java,
you
create
specialized
subclasses
–
in
ObjecCve
C,
you
delegate
14
iOS
app
logical
structure
15
iOS
app
life
cycle
16
XCode
and
Interface
Builder
•
IDE
=
Integrated
Development
Environment
•
XCode
is
Apple’s
IDE
for
iOS
and
Mac
OS
development
•
Code
compleCon,
online
help,
debugger,
deployment
to
target
device,
…
•
Interface
Builder
for
building
the
UI
•
Instruments
for
profiling
and
analyzing
•
iPhone/iPad
emulator
for
tesCng
•
Also
used
to
manage
developer
idenCCes
•
Must
have
a
developer
idenCty
to
deploy
apps
to
real
devices
•
Developer
idenCty
obtained
from
Apple
Store,
67
€
/
year
•
XCode
3
is
free
for
everyone,
new
XCode
4
costs
4
€
for
non-‐developers
•
Registered
(i.e.
paid)
developers
get
the
new,
streamlined
IDE
for
free
•
Based
on
screen
shots,
worth
the
investment
17
Ge5ng
ready
to
develop
•
Follow
instrucCons
in
hNp://developer.apple.com/
•
Download
XCode
3
or
4,
your
preference
•
Run
the
installer
•
OpConally:
run
XCode
and
enter
your
developer
informaCon
•
Required
to
deploy
apps
to
real
devices
•
Real
devices
are
recognized
when
they
are
plugged
in
•
The
download
is
4+
GB
•
InstallaCon
takes
another
30..45
minutes
but
is
generally
painless
18
Step 1: Get started
Step 2: …
Step 3: Victory!
19
App
Elements
The
Info.plist
file
•
The
Info.plist
defines
your
applicaCon
•
Display
name
of
your
applicaCon
•
Executable
name
of
your
applicaCon
•
Device
environment
that
your
applicaCon
may
require
(
iPhone/iPad
)
•
Main
.nib
file
name
to
load
your
UI
from
(created
by
Interface
Builder)
•
UIRequiredDeviceCapabiliCes
to
require
GPS,
Camera,
etc.
•
Cannot
request
all
differenCaCng
factors,
some
need
to
be
checked
in
code
•
Important,
but
much
simpler
than
an
Android
Manifest
•
Rarely
need
to
touch
the
XCode
generated
file
20
Resources
•
Stored
in
subdirectory
Resources
in
your
applicaCon
source
tree
•
Drawables
:
icons,
bitmaps
•
Layouts
and
menus:
XML
view
definiCons
(the
.nib
and
.
xib
files)
•
Strings:
a
.strings
plain
text
file
mapping
logical
names
to
values
•
LocalizaCon
•
Get
Info
on
a
resource
file
in
XCode
,
click
Make
Localizable
•
Generates
a
copy
you
can
localize,
including
UI
layouts
and
graphics
•
LocalizaCon
should
be
done
only
a^er
your
UI
layouts
are
final
•
Command
line
tool
ibtool
can
be
used
to
synchronize
updates
•
Results
in
Language1.lproj
,
Language2.lproj
subdirectories
in
your
app
bundle
•
System
will
load
resources
from
current
language
.
lproj
–
or
use
the
development
language
defined
in
your
Info.plist
if
the
localizaCon
is
not
found
21
Source
files
•
The
.
h
files
for
declaraCons,
.
m
files
for
code
•
Forward
declaraCons
using
@class
name
•
Interface
declaraCons
using
@interface
name
…
@end
•
Class
member
accessor
declaraCons
using
@property
(…)
name
•
Headers
included
using
tradiConal
#include
“
filename
”
•
ImplementaCon
using
@implementaCon
name
…
@end
•
Class
member
accessor
implementaCons
using
@synthesize
name
•
AppDelegate
implements
life
cycle
methods
•
Including
instanCaCng
your
iniCal
view
•
ViewController
binds
your
views’
UI
elements
to
your
data
and
logic
•
Implements
the
behavior
of
your
app
22
23
CreaCng
and
Deploying
an
App
Basic
steps
•
In
XCode
,
File
-‐>
Create
New
Project,
iOS
ApplicaCon
•
Select
the
View-‐based
ApplicaCon
to
get
a
View
and
a
Controller
•
XCode
generates
the
directory
structure
and
skeleton
files
for
you
•
Add
funcConality
to
your
ObjC
code
•
For
example,
a
buNon
click
handler
•
Add
resources
•
For
example,
a
picture
(drag-‐and-‐drop
to
Resources
folder)
•
Open
the
.
xib
file
and
add
some
user
interface
elements
•
E.g.
a
buNon;
bind
your
code
objects
to
UI
objects
with
drag-‐and-‐drop
•
Run
your
app!
•
Either
in
emulator,
or
over
USB
on
your
iOS
device
(if
you
have
paid!)
24
XCode
:
create
iOS
project
25
XCode
:
project
structure
26
XCode
:
add
UI
elements
27
XCode
:
add
resources
28
IB:
Add
UI
elements
29
IB:
Bind
code
to
UI
30
Right-click
Drag the circle to
the UI object to bind to
XCode
/IB:
localizaCon
31
The last step is to edit all .
xib
file
variants in Interface Builder for
proper localization.
XCode
:
run
on
Target!
32
Click the “Run” button
in the
XCode
toolbar.
If you have an
iOS
device, your app can run
directly in your device.
Choose your target in
XCode
.
33
Advanced
programming
topics
State
saving
•
When
user
presses
the
Home
buNon,
•
In
iOS
3,
your
app
will
be
killed
–
iOS
invokes
your
delegate’s
applica;onWillTerminate
•
In
iOS
4,
your
app
will
remain
in
memory
–
iOS
invokes
your
delegate’s
applica;onDidEnterBackground
•
Even
in
iOS
4,
if
resources
become
scarce,
your
app
will
be
killed
•
Best
to
save
state
in
a
dicConary
(name,
value
pairs)
whenever
either
state
change
method
is
invoked
by
iOS
•
When
your
app
starts
up
•
In
your
delegate’s
applica;on:didFinishLaunchingWithOp;ons
method,
read
and
restore
your
state
data
from
the
parameter
dicConary
(if
not
nil
)
•
Data
stored
as
(an
XML
format)
plist
in
your
app
configuraCon
area
34
Game
programming
•
iOS
apps
run
naCve
code
•
Maximum
performance
•
All
hardware
resources
in
use
•
Direct
access
to
OpenGL
ES
•
Complex
3D
user
interfaces
possible
•
Need
to
honor
the
app
life
cycle
noCficaCons
•
Immediately
stop
animaCons,
sounds,
etc
when
told
to
go
to
background
•
Device
must
react
to
incoming
calls,
SMS,
etc
immediately
35
36
DistribuCng
your
App
The
App
Store
•
The
definiCve
on-‐line
app
store
•
300000
app
Ctles
(Android:
200000)
•
62000
unique
developers
(Android:
180000)
•
33%
free
apps,
66%
paid
apps
(Android:
60%
free,
40%
paid)
•
Average
paid
app
price
in
2010:
$2,43
•
50%
of
apps
between
$0,99
..
$2,99,
only
1%
at
$24,99
or
more
•
30%
of
revenue
goes
to
Apple,
70%
to
developer
(out
of
which
you
pay
taxes)
•
The
67
€
/
year
fee
buys
you
fairly
good
QA
•
Easy
to
submit
apps
to
the
Store
•
Apple
engineers
verify
that
your
app
works,
keeps
quality
high
•
Apple
has
a
strict
acceptance
policy
•
Any
content
which
might
get
Apple
into
liability
court
is
rejected
/
removed
37
In
Conclusion
•
Apple’s
iOS
sets
the
bar
for
others
•
Harded
to
get
into
than
Android
–
ObjecCve-‐C
language
and
fairly
complicated
design
paNerns
required
•
NaCve
code
runs
efficiently,
maximum
performance
and
capabiliCes
•
Has
a
reputaCon
of
high
quality,
people
expect
that
and
are
willing
to
pay
•
Developer
tools
extensive
but
fairly
complicated
•
New
XCode
4
streamlines
development
•
Excellent
and
extensive
documentaCon
•
Sample
code
in
developer
portal
(requires
membership
=
money)
•
Rich
and
mature
APIs
•
Data
access,
mulCmedia,
wireless
services,
…
•
Reasonably
easy
to
create
simple
apps,
complex
apps
require
liNle
more
38
39
Quick
IntroducCon
to
WP7
Windows
Phone
7
basics
•
Based
on
Windows
CE
6.0,
replaces
clunky
Windows
Mobile
6.5
•
All
APIs
now
.NET
based,
no
direct
C/C++
API
•
Simple
apps
using
Silverlight
and
C#
assemblies
•
Games
using
XNA
and
C#
assemblies
•
Strict
conformance
requirements
for
devices
•
800x480
mulCtouch
display,
512
MB,
armv7,
camera,
hardware
keys,
…
•
Very
specific
look
and
feel,
which
cannot
be
skinned
by
device
vendors
•
Microso^’s
aNempt
to
curb
variance
and
fragmentaCon
of
app
ecosystem
•
Limited
possibility
for
device
vendors
to
differenCate
from
others
•
Many
device
vendors
embracing
WP7
•
LG,
Samsung,
most
famously
now
also
Nokia
•
Trust
that
Microso^’s
markeCng
muscle
will
sell
devices
40
WP7
APIs
•
For
simple
apps:
Silverlight
•
XML-‐based
UI
declaraCon
+
C#
code
–
executed
in
.NET
CLR
•
Vector
based
UI
widgets
•
NavigaCon
framework,
event
based
input
•
Basically,
Microso^’s
version
of
Flash
•
For
games:
XNA
•
C#
code
–
executed
in
.NET
CLR
•
Direct3D
–
every
frame
is
redrawn
in
full
•
Shaders
,
GPU
acceleraCon,
polling
based
input
•
Basically,
same
as
in
XBox
41
This combination is very
similar to Android’s XML
and Java approach.
Games should translate
fairly well between the
XBox
and WP7 devices.
Developer
Tools
•
Microso^
Windows
Phone
Developer
Tools
–
free
of
charge
•
Basic
set
for
C#
developers
–
add-‐on
for
Visual
Basic
developers
•
Windows
7
required
42
CreaCng
the
UI
43
Binding
to
code
44
<Button Height="150” Width="300” Name="
FirstButton
” Content="Tap" />
private void
FirstButton_Click(object
sender,
RoutedEventArgs
e
)
{
if (
FirstButton.Content
as string == "Tap")
{
FirstButton.Content
= "Tap Again";
}
else
{
FirstButton.Content
= "Tap";
}
}
App
DistribuCon
•
Windows
Phone
Marketplace
•
$
99
/
year
registraCon
fee
•
RelaCvely
few
apps
in
there
so
far
•
Upload
procedure
straighEorward
from
Visual
Studio
•
Microso^
does
cerCficaCon
tesCng
before
submi5ng
the
app
to
the
store
•
Only
Microso^-‐signed
apps
can
run
on
the
devices
•
Microso^
is
heavy
on
EULAs
•
When
you
use
a
WP7
device,
there
is
small
print
everywhere
•
Similar
small
print
applies
to
any
app
submissions
–
Microso^
is
just
as
careful
about
liCgaCon
as
Apple
45
46
Brief
Comparison
Food
for
thought
Android
iOS
WP7
Symbian
Units sold in
2010
67 million
47 million
12 million
111 million
Device
Variants
Many
Some
None
Many
Easy if you
know…
Java
Objective C
C# or
Silverlight
Qt and C++,
or Java
Dev platform
Linux, Mac,
Windows
Mac
Windows
Linux, Mac,
Windows
Cost to
Develop
Free
Free
Free
Free
Cost to
distribute
Free
$99 / year
$99 / year
1 €
Competition
in app space
Fierce
Fierce and
controlled
Not much
Not much
47
Units sold data: Gartner, Feb 2011
48
Σχόλια 0
Συνδεθείτε για να κοινοποιήσετε σχόλιο