Professional Documents
Culture Documents
martino ruggiero@unibo it
martino.ruggiero@unibo.it
Important Announcement
• The iPhone Programming lessons are strictly
related to the MPHS course
• We received tens of external requests for
attendingg the lessons, but the classroom has a
limited number of seats
• External attendees are kindly requested to leave
their seats to MPHS students
• We are organizing an open seminar into a
bigger room
• Thank you for your help!
Material and acknowledgements
• Stanford iPhone Application Programming course:
– http://www.stanford.edu/class/cs193p/cgi-bin/index.php
• WebPages and blogs:
• iPhoneitalia
• iSpazio
• Etc.
• iPhone Dev Center:
• http://developer.apple.com/iphone/
• The following documents provide key information related to iPhone
p
development:
• Cocoa Fundamentals Guide provides fundamental information about the design patterns and practices
used to develop iPhone applications.
• iPhone Application Programming Guide provides an architectural overview of iPhone applications along
with practical guidance on how to create them.
• iPhone Human Interface Guidelines provides guidance and important information about how to design
your iPhone application’s user interface.
• iPhone Development Guide provides important information about the iPhone development process from
the tools perspective. This document covers the configuration of devices and the use of Xcode (and other
tools) for building
building, running,
running and testing your software.
software
• The Objective-C Programming Language introduces Objective-C and the Objective-C runtime system,
which is the basis of much of the dynamic behavior and extensibility of iPhone OS.
What is iPhone
Let’s
Let s take a look inside
inside….
video, autofocus,
compass, more speed & Yes
RAM
The CORTEX
CORTEX-A8
A8 Microprocessor
• On-chip
On chip L1 and L2
• 2 ALU pipes
• NEON media engine
• Jazelle
• Thumb-2
Memory hierarchy
• M i S
Main System
t Memory
M
• The iPod Touch "1G"/"2G" and iPhone "2G"/3G have 128MB of main working
memory (RAM).
• Th iP
The iPod
d Touch
T h "3G" and
d iPh
iPhone 3GS hhave 256MB off RAM.
RAM
• Storage Flash Memory
• The iPod Touch and iPhones mainly contains from 4GB to 64GB of NAND flash
storage
t memory.
• The iPod Touch "3G" has a 64GB model (from Toshiba)
• Apple decided to leave out a flash memory card slot and force users to choose
iPh
iPhone models
d l bbasedd on fifixed
d amountt off non-removeable
bl flash
fl h memory.
• Firmware Flash Memory (from 4MB to 16MB)
– In addition to regular storage flash memory, the iPhone also has additional NOR
fl h memory to
flash t store
t bootup
b t code d (similar
( i il to
t BIOS iin PC)
PC).
– This data usually holds the minimum operating system for booting up the device.
After booting up it lets other instructions stored in the storage flash memory to
take over
over.
Other on-board
on board peripherals
• GPS
– The iPhone 3G/3GS have assisted GPS (A-GPS) using the Infineon PMB 2525
(Hammerhead II) chipset. A-GPS means that there are many ways to obtain your location
besides reading the multiple GPS geosynchronous satellites signals broadcasted in 1.57542
GHz. When you turn ON the "Location Services", there are three major ways the iPhone gets
your location: Satellite GPS, Cell Tower Triangulation, and WPS.
• Accelerometer
– 3-axis accelerometer from STMicroelectronics, which detects rotation and orientation.
– N t that
Note th t with
ith this
thi chip
hi alone
l you are onlyl able
bl tto ttellll your position
iti iin 3D iin relation
l ti tto gravity.
it
– Gravity cannot tell you information on direction your iPhone is pointing if resting on a table.
• Magnetometer
– The iPhone 3GS also contains a 3-axis electronic compass from an AKM chip (Asahi Kasei
AK8973), which allows detection of the direction of magnetic north. In companion with GPS
data, it allows for hardware assisted turn-by-turn GPS.
• Ambient Light Sensor
– The iPhone and iPod Touch have an ambient light sensor near the top of of the device. This
sensor detects the amount of light so it can adjust the brightness of the LCD to save battery
life.
• Proximity Sensor
– All iPhones have a proximity sensor near the top left of the device. It detects when your face
is close to the phone so that the screen can by powered off to save battery life.
Which Type of Applications?
• Users can run two diff
U different types off custom applications
li i on a
device:
– web applications
pp
– native applications.
• Web applications use a combination of HTML, cascading style
sheets and JavaScript code to implement interactive applications
sheets,
that live on a web server and are transmitted over the network and
run inside the Safari web browser.
• Native applications, on the other hand, are installed directly on the
device and can run without the presence of a network connection.
iPhone SDK
• The iPhone SDK contains the tools and interfaces
needed to develop, install, and run custom native
applications.
applications
• Native applications are built using the iPhone OS system
frameworks and the Objective
Objective-CC language and they run
directly on iPhone OS.
– Unlike web applications, native applications are installed
physically on a device and can run with or without the presence
of a network connection.
– They reside next to other system applications and both the
application and any user data is synced to the user’s computer
through iTunes.
What Can You Create?
• The iPhone
Th iPh SDK supports the h creation
i off native
i fforeground d
applications that appear on the device’s Home screen only.
• The iPhone SDK does not supportpp the creation of other types
yp of
code, such as:
– Drivers,
– Background
B k d applications,
li ti
– Dynamic libraries.
– If you want to integrate code from a dynamic library into your
application, you should link that code statically into your
application’s executable file when building your project.
Xcode Tools
• It provides
id ththe ttools
l th
thatt supportt iPhone
iPh application
li ti d development,
l t iincluding
l di
the following key applications:
– Xcode: an integrated development environment that manages your application
projects
j t and d llets
t you edit,
dit compile,
il run, anddddebug
b your code. d Xcode
X d integrates
i t t
with many other tools and is the main application you use during development.
– Interface Builder: a tool you use to assemble your user interface visually. The
interface objects you create are then saved to a special resource file format and
loaded into your application at runtime.
– Instruments: a runtime performance analysis and debugging tool. You can use
Instruments to g gather information about yyour application’s runtime behavior and
identify potential problems.
• Xcode and Instruments also let you interact directly with an attached device
to run and debug your code on the target hardware.
• Development on an actual device requires signing up for Apple’s paid
iPhone Developer Program and configuring a device for development
p p
purposes.
Xcode
Interface Builder
• I
Interface
f Builder
B ild iis the
h tooll you use to assemble
bl your application’s
li i ’ user
interface visually.
• Using Interface Builder, you assemble your application’s window by
dragging and dropping preconfigured components onto it.
• The components include standard system controls such as switches, text
fields, and buttons, and also custom views to represent the views your
application provides.
• After you’ve placed the components on the window’s surface, you can
position them by dragging them around, configure their attributes using the
inspector, and establish the relationships between those objects and your
code.
Instruments
Application
iPhone OS Technologies
• The iPhone
Th iPh OS uses a ffairly
i l straightforward
i hf d software
f stack.
k
• At the very bottom of this stack is the Mach kernel and hardware
drivers,, which manage g the overall execution of p
programs
g on the
device.
• On top of that layer are additional layers that contain the core
technologies and interfaces you use for development
development.
• Although iPhone OS does not expose any of the kernel or driver-
level interfaces, it does expose technologies at the higher levels of
the stack.
Layers of iPhone OS
Cocoa in
iPhone OS (touch) and Mac OS X
• C
Cocoa presents two ffaces:
– a runtime aspect: Cocoa applications present the user interface and
are tightly integrated with the other visible portions of the operating
system;
• on Mac OS X, these include the Finder, the Dock, and other applications
from all environments.
– a development aspect: Cocoa is an integrated suite of object-oriented
software components (classes) that helps in creating robust, full-
featured applications.
• These classes are reusable and adaptable software building blocks;
• You can build Cocoa applications for two platforms:
– the Mac OS X Cocoa
– iPhone OS Cocoa Touch
• Generally, the system libraries and frameworks of iPhone are a subset of the
libraries and frameworks on Mac OS X X.
Cocoa Touch Layer
• C
Cocoa T
Touch
h is
i one off the
h most iimportant llayers iin iPhone
iPh OS
OS.
– It comprises the key frameworks that provide the infrastructure you
need to implement applications in iPhone OS.
• When developing your applications, you should always start with
these frameworks and drop down to lower-level frameworks only as
needed.
needed
• It is composed by:
– Apple Push Notification Service
– Address Book UI Framework
– In App Email
– Map Kit Framework
– Peer to Peer Support
– UIKit Framework
Media Layer
• IIn the
h Media
M di layer
l are the
h graphics,
hi audio,
di and
d video
id technologies.
h l i
• The high-level frameworks in iPhone OS make it easy to create
advanced ggraphics
p and animations qquickly
y
• It is composed by:
– Graphics Technologies
• Quartz
Q t
• Core Animation
• OpenGL ES
– Audio Technologies
• AV Foundation
• Core Audio
• OpenAL
O AL
– Video Technologies
Core Services Layer
• Core S
C Services
i provides
id theh ffundamental
d l system services
i that
h allll
applications use.
• Even if yyou do not use these services directly,
y, manyy parts
p of the
system are built on top of them.
• It is composed by:
– Address B
Add Bookk
– Core Data
– Core Foundation
– Core Location
– Foundation Framework
– In App Purchase
– SQLite
– XML Support
Core OS Layer
• The Core
Th C OS layer
l encompasses the th kkernell environment,
i t ddrivers,
i
and basic interfaces of the operating system
The Event-Handling
Event Handling Cycle
The Application Runtime
Environment
• F t Launch,
Fast L h Short
Sh t Use
U
– only one foreground application runs at a time
– application must launch and initialize itself quickly, and be prepared to exit quickly
• The Application Sandbox
– a set of fine-grained controls limiting an application’s access to files, preferences,
network resources, hardware, and so on.
– for security reasons, iPhone OS restricts an application to a unique location in the
file system.
• The Virtual Memory System
– each program still has its own virtual address space, but its usable virtual memory
is constrained by the amount of physical memory available.
– iPhone OS does not write volatile pages to disk when memory gets full.
• The Automatic Sleep Timer
– to save power, but developers can disable it only applications that do not rely on
touch inputs but do need to display visual content on the device’s screen.
– If the system does not detect touch events for an extended period of time, it dims
the screen initially and eventually turns it off altogether.