iOS Development Tutorial
Nikhil Yadav
CSE 40816/60816: erva!ive "ealth
0#/0#/$011
"ealth%are ihone app!
&ariou! app! 'or the ihone availa(le
Dia)no!ti%* Diet and Nutrition* +itne!!* Emotional
,ell-(ein) e.). ,e(/D mo(ile.
0e1uirement!
2pple /a% Computer 3De!ktop or laptop4 5ith
re%ent Sno5 6eopard/6ion (uild! 37810.64
2pple Developer 0e)i!tered ro'ile 3%reate an
a%%ount at http://developer.apple.%om4
2pple ihone SD9 3%an (e do5nloaded 'rom:
http://developer.apple.%om/dev%enter/io!/ under
:%ode and iOS SD9 4.1 and hi)her4
;o to http://developer.apple.%om %reate an
a%%ount i' <ou do not alread< have one
/ail the e-mail a%%ount <ou u!ed to re)i!ter
<our!el' to me
You 5ill (e invited throu)h e-mail to (e a part
o' the iphone developer team. Con'irm
a%%eptan%e.
2pple Developer 0e)i!tration
2pple Developer Site 2%%e!!
Ne=t time <ou lo) in to apple developer !ite it
5ill look !imilar to:
Sele%t ihone Developer ro)ram ortal
2pple Devi%e >D
3Skip thi! part i' <ou are u!in) one o' the Cla!! provided ihone! or iod
tou%he!4
>' <ou are u!in) <our o5n ihone* )et the
devi%e >D throu)h :%ode?! or)ani@er. /ail the
Devi%e >D to u!
2pple Development Certi'i%ate
Ne=t <ou have to )enerate a %erti'i%ate !i)nin)
re1ue!t
6aun%h the 9e<%hain a%%e!! on <our %omputer*
it i! lo%ated here:
Then )o to the 9e<%hain 2%%e!! / Certi'i%ate
2!!i!tant / 0e1ue!t a Certi'i%ate 'rom a
Certi'i%ate 2uthorit< menu item.
/ake !ure <ou %li%k on the A!aved to di!kA
(u((le* !o that <ou donAt have to enter a C2
Email 2ddre!!
+ill out the re!t o' the in'ormation* hit %ontinue*
and !ave the %erti'i%ate !ome5here on <our
%omputer that <ou 5ill remem(er. Then* itA! (a%k
to the the provi!ionin) a!!i!tant.
Do5nload the provi!ionin) pro'ile 5hen
prompted. 2nd then dou(le %li%k on it
Dou(le %li%kin) on <our pro'ile !hould open up
:%ode and add it to <our devi%e* i' it doe!nAt
open =%ode* dra) the provi!ion to =%ode.
If it doesnt add it to your device, its possible you mistyped your devices UDID. This can be fixed after youve
finished going through this tutorial by going back to your program portal, going to the devices tab, and
changing the id in there, and then redo!nloading your profile in the distribution tab.
Do5nload <our %erti'i%ate in an ea!< to
remem(er lo%ation
ortin) to a%tual ihone devi%e
Con!ider the 'ollo5in) !ample appli%ation 3open
it up in :%ode4
Cli%k on the arro5 ne=t to BTar)et!A* and then dou(le
%li%k on the tar)et name 3in thi! %a!e Bihone o+A4
Cli%k on Cuild in the 5indo5 that open!.
>n thi! 5indo5* %li%k on the %on'i)uration! and
!ele%t all %on'i)uration!
Then )o do5n to 5here the Code Si)nin)
>dentit< line i!. 2%ro!! 'rom 2n< ihone OS
Devi%e* %li%k on 5here it !a<! ihone
Developer: (developer name)
Sele%t Bihone DeveloperA 'rom the automati%
pro'ile !ele%tor!. Thi! !hould make the %urrent
automati% !ele%tion (e <our pro'ile.
Clo!e that 5indo5* and %li%k the trian)le ne=t to
the data 'older. Dou(le %li%k on the in'o.pli!t 'ile
0epla%e the (undle identi'ier 5ith:
?%om.perva!ivehealth.mo(ileapp!?
Clo!e and !ave the pli!t 'ile* and hit Compile.
>' <ou are on !no5 leopard 5ith the ne5 !dk and 5e
havenAt updated the e=ample! <et <ou ma< need to
%han)e <our (a!e SD9 to 4.0 !o that itA! not mi!!in).
Thi! %an (e done in the tar)et !ettin)!. 2l!o* <ou 5ill
have to %li%k on 5here it !a<! Bdevi%e D $.$ E de(u)A in
the !%reen!hot a(ove* and %han)e that to Devi%e D 4.0
E De(u) or an< o' the ne5er devi%e !ettin)! dete%ted
on <our phone
>' ever<thin) 5ork! properl<* :%ode 5ill a!k to
%ode!i)n 'rom <our ke<%hain. "it B2l5a<! 2llo5A.
ihone lat'orm
20/ ro%e!!or
1$8/$F6 /C 02/
CSD GN>:
/a%h /i%rokernel
COCO2 2>!
COCO2
COCO2 i! a OO +rame5ork
Ca!ed on Ne=tStep
/o!tl< 5ritten in O(He%tive-C
ihone u!e! COCO2 Tou%h
COCO2 +rame5ork
NS 3Ne=tStep4
C+ 3Core +oundation4
C2 3Core 2nimation4
C> 3Core >ma)e4
Core Data
Open;6
COCO2 Convention!
/o!t %la!!e! (e)in 5ith NS* >.E. NSO(He%t*
NSStrin)* NS2rra< or NSNum(er
De!i)ned around /&C pattern
"eav< u!e o' dele)ation
ihone !pe%i'i% %omponent! (a!ed on G>9it
COCO2 Tou%h 2>!
2%%elerometer
6o%ation 2>
/ulti-Tou%h
Camera/&ideo >nput
/ap >nter'a%e
Open;6 ES
O(He%tive-C
Some5here in-(et5een CII and Java
>nvented in 1#80A! 'or Ne=t Computin)
Ca!ed on C 5ith SmallTalk like e=tention!
G!ed in COCO2* OpenStep and ;NGStep
Cla!! (a!ed OO lan)ua)e
O(H-C v! CK
O(H-C CK
LLo(He%t methodM methodMN o(H.method34.method34N
/emor< ool! ;ar(a)e Colle%tion
I/- !tati%/in!tan%e
nil null
3void4method,ith2r):3int4value OP void method3int value4 OP
YES NO true 'al!e
Qproto%ol
inter'a%e
O(He%tive-C Stru%ture
O(H-C Cla!! %ompo!ed o' t5o 'ile!: header
and implementation* or .h and .m
header u!e! the Qinter'a%e and
implementation u!e! Qimplementation
#import <UIKit/UIKit.h>
@interface LottoRandomAppDelegate : N!"#ect <UIApplicationDelegate>$
UI%indo& '&indo&(
)
@propert* +nonatomic, retain- I.!/tlet UI%indo& '&indo&(
@end
#import 0LottoRandomAppDelegate.h0
@implementation LottoRandomAppDelegate
@1*nthe1i2e &indo&(
3 +4oid-applicationDid5ini1hLa/nching:+UIApplication '-application $
// !4erride point for c/1tomi2ation after application la/nch
6&indo& ma7eKe*And8i1i"le9(
)
3 +4oid-dealloc $
6&indo& relea1e9(
61/per dealloc9(
)
@end
3+.!!L-4alidateN/mRange%ithtartN/m"er:+int-1tartN/m"er :ndN/m:+int-
endN/m"er
$
if +1tartN/m"er >; endN/m"er-
$
UIAlert8ie& 'alert8ie& ; 66UIAlert8ie& alloc9
init%ith<itle:@0:nd 4al/e <oo mall0
me11age:@0orr*0
delegate:nil
cancel./tton<itle:@0!K0
other./tton<itle1:nil9(
6alert8ie& 1ho&9(
6alert8ie& relea1e9(
ret/rn =:(
) el1e $
ret/rn N!(
)
)
Sele%tor!
SE6 t<pe de'ine! a method !i)nature
-3void4!et2%tion:3SE64aSele%tor
SE6 m<Sele%torN
m<Sele%tor 8 Q!ele%tor3dra5/<&ie5:4N
Lm<Cutton !et2%tion:m<Sele%torMN
/emor< /ana)ement
C u!ed method! like mallo% and 'ree
O(H-C u!e! o(He%t retain pool
;ar(a)e Colle%tion on the /a%* (ut not on the
ihone
>nherit mana)ement method! 'rom NSO(He%t
/emor< /ana)ement Cont.
NSStrin) Rm<Name 8 LLNSStrin) allo%M initMN
// retain %ount o' 1
Lm<Name retainMN
// retain %ount o' $
Lm<Name relea!eMN
// retain %ount redu%ed to 1
Lm<Name autorelea!eMN
// o(He%t relea!ed (< pool ma)i%all<
/&C
/odel-&ie5-Controller
COCO2 ha! Controller %la!!e!
G>&ie5Controller Cla!!
&ie5! are in the :>C 3N>C4 'ile!
Controller!
ihone 2pp! %ommonl< have multiple vie5!
u!h and op the Controller! 'or ea%h &ie5
Navi)ation Controller u!ed to load di''erent
vie5!
G>Navi)ationController
SD9 Tool!
:%ode 4.1 3and 74 >DE
>nter'a%e Cuilder 3&ie5!4
>n!trument! 3ro'iler tool4
ihone Simulator
>nter'a%e Cuilder
Tool 'or la<in) out inter'a%e!
Separate Tool 'rom :%ode
Cind 2%tion! and Outlet! in Controller!
Demo
&ie5 Ca!ed 2ppli%ation
Open the :%ode and %li%k on +ile 7 Ne5
roHe%t. Sele%t S&ie5-Ca!ed 2ppli%ationT and
%li%k on SChoo!e..T (utton. Name thi! proHe%t
S"ello ,orldT and %li%k SSaveT (utton. No5
<ou have a template 'or <our hello 5orld
iphone proHe%t.
No5 %li%k on Cuild and ;o (utton to run thi!
template appli%ation. >t 5ill !tart the ihone
!imulator and <ou %an !ee a )ra< !%reen on
that. Cli%k on "ome (utton and it 5ill !ho5
<ou a "ello,orld i%on on the da!h (oard o'
ihone !imulator. >' <ou %li%k on it a)ain* it 5ill
open the appli%ation a)ain. ihone !imulator
i! (e!t tool to te!t <our appli%ation (e'ore <ou
deplo< it on <our devi%e 'or te!tin) or even
(e'ore !u(mittin) to apple !tore.
Open :%ode roHe%t and edit
"ello,orld&ie5Controller.h
Kimport UG>9it/G>9it.h7
Qinter'a%e "ello,orld&ie5Controller : G>&ie5Controller O
>COutlet G>Te=t+ield Rt=tG!erNameN
>COutlet G>6a(el Rl(lG!erT<pedNameN
P
- 3>C2%tion4 !u(mitYourNameN
Qend
No5 open "ello,orld&ie5Controller.m 'ile
and t<pe thi! method (e'ore Qend
- 3>C2%tion4 !u(mitYourNameNOl(lG!erT<pedName.te=t 8 t=tG!erName.te=tNP
No5 let! !tart !ome de!i)n on inter'a%e
(uilder. Open <our =%ode proHe%t and in
S;roup V +ile!T looked at (ottom* <ou 5ill !ee
SN>C +ile!T* e=pand it and <ou 5ill !ee t5o
de!i)n 'ile! 'or <our %la!!e!. One i! the
/ain,indo5.=i( 5hi%h i! the main 5indo5 or
entr< point to <our appli%ation. Other one i!
"ello,orld&ie5Controller.=i( 'ile 5hi%h i!
mapped to <our %ontroller %la!!
S"ello,orld&ie5Controller.h. +or no5 5e Hu!t
5ant to %han)e in
"ello,orld&ie5Controller.=i( 'ile. Dou(le %li%k
on that 'ile to open it in!ide inter'a%e (uilder.
Cli%k on Tool! and !ele%t 6i(rar< 3%md I !hi't
I 64 and dra) the te=t 'ield to <our vie5. 2!
te=t 'ield i! alread< !ele%ted* %li%k on
Tool!7>n!pe%tor 3%md I 14 and in Te=t 'ield
t<pe SYour NameT.
No5 dra) the Te=t+ield 'rom 6i(rar< to <our
vie5 3%mdI!hi'tI64 and al!o dra) another
6a(el in!ide vie5. /ake !ure la(el i!
!ele%ted* Cli%k on tool! and !ele%t SSi@e
>n!pe%torT 3%md I W4 and %han)e the 5idth o'
thi! te=t 'ield to $F0. 2l!o )o to tool! and
!ele%t >n!pe%tor* %han)e the la<out to %enter.
6a!t thin) i! to dra) a (utton to the vie5 31#4 and then open
>n!pe%tor a)ain (< !ele%tin) tool!7>n!pe%tor. >n Title t<pe
SSu(mitT.
No5 map the %ontroller %la!! varia(le 'un%tion and method! 5ith
inter'a%e (uilder. Sele%t +ileA! O5ner in >nter'a%e (uilder and !ele%t
%onne%tion in!pe%tor 'rom Tool! %md I $
No5 <ou %an !ee that t5o ne5 varia(le! are
added in %onne%tion in!pe%tor t=tG!erName
and l(lG!erT<pedName. Cli%k on
t=tG!erName radio (utton and dra) it to te=t
'ield in vie5 3a! <ou %an !ee in the ima)e4
Do the !ame 5ith l(lG!erT<pedName* !ele%t
it! radio and dra) it to (elo5 la(el.
No5 the la!t !tep i!* %li%k on
!u(mitYourName radio and dra) it to the
(utton and !ele%t tou%h do5n 'rom the li!t.
No5 %lo!e the inter'a%e and open =%ode.
Either pre!! %md I r or %md I enter or !impl<
pre!! o' S(uild and )oT (utton to run thi! hello
5orld appli%ation. >t 5ill open the !imulator in
ihone.
0e!our%e!
http://developer.apple.com/
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html
http://www.cocoadev.com/