Tải bản đầy đủ

OReilly IPhone open application development write native objective c applications for the IPhone mar 2008 ISBN 0596518552

iPhoneOpenApplicationDevelopment
byJonathanA.Zdziarski
Publisher:O'Reilly
PubDate:March15,2008
PrintISBN-13:978-0-59-651855-4
Pages:280
TableofContents|Index

Overview
Certaintechnologiesbringouteveryone'shiddengeek,andthe
iPhonedidsoinstantlyuponitsrelease.Thousandsof
programmerswanttoprovideapplicationsontheiPhone,and
thisbookshowsyouhowtoachievethespectaculareffectsthat
madethedeviceanimmediatehit.You'lllearnhowtousean
open,community-developedtoolkitthathasbeenwidely
downloadedandused.AuthorJonathanZdziarski,thedeveloper
ofthefirstfullyfunctionalapplicationusingtheopeniPhone
toolkit,nowexplainsinclearlanguagehowtocreate
applicationsusingObjective-CandtheiPhoneAPI,whichin
somewaysresemblesApple'sdesktopAPIandinsomeways
strikesnewground.iPhoneOpenApplicationDevelopment

covers:
Installationofthetoolkits
BackgroundontheoperatingsystemandObjective-C
Detailedrecipesandworkingexamplesforeveryone's
favoriteiPhonefeature
Graphicsandaudioprogramming
TheCoreImageandCoreSurfacesinterfacesforgames
programming
InterfacingwithiTunes


Theuseofsensors
Anyprogrammer,usingthisbook,canprovideapplicationsthat
impressusersjustasmuchastheofficialiPhoneutilities.


iPhoneOpenApplicationDevelopment
byJonathanA.Zdziarski
Publisher:O'Reilly
PubDate:March15,2008
PrintISBN-13:978-0-59-651855-4
Pages:280
TableofContents|Index

Copyright
preface
Chapter1.BreakingIntoandSettingUptheiPhone
Section1.1.JailbreakProcedures
Section1.2.InstallingBSDSubsystem
Section1.3.AdditionalResources
Chapter2.GettingStartedwithApplications
Section2.1.AnatomyofanApplication
Section2.2.BuildingtheFreeToolChain
Section2.3.BuildingandInstallingApplications
Section2.4.IntegratingwithXCode
Section2.5.TransitioningtoObjective-C
Chapter3.IntroductiontoUIKit
Section3.1.BasicUserInterfaceElements
Section3.2.WindowsandViews
Section3.3.TheMostUselessApplicationEver


Section3.4.DerivingfromUIView
Section3.5.TheSecondMostUselessApplicationEver
Section3.6.TextViews
Section3.7.NavigationBars
Section3.8.TransitionViews
Section3.9.AlertSheets
Section3.10.Tables


Section3.11.StatusBarManipulation
Section3.12.ApplicationBadges
Section3.13.ApplicationServices
Chapter4.EventHandlingandGraphicsServices
Section4.1.IntroductiontoGeometricStructures
Section4.2.IntroductiontoGSEvent
Section4.3.Example:TheIconShuffle
Chapter5.AdvancedGraphicsProgrammingwithCoreSurface
andLayerKit
Section5.1.UnderstandingLayers
Section5.2.ScreenSurfaces
Section5.3.LayerAnimation
Section5.4.LayerTransformations
Chapter6.MakingSomeNoise
Section6.1.CoreAudio:It'sGreat,butYouCan'tUseIt
Section6.2.Celestial
Section6.3.AudioToolbox
Chapter7.AdvancedUIKitDesign
Section7.1.Controls
Section7.2.PreferencesTables
Section7.3.ProgressIndicators
Section7.4.UIProgressBar:WhenSpinnyThingsAreTacky
Section7.5.ProgressHUDs:WhenIt'sImportantEnoughto
BlockStuff
Section7.6.ImageHandling
Section7.7.SectionLists
Section7.8.Keyboards
Section7.9.Pickers
Section7.10.Date/TimePickers
Section7.11.ButtonBars
Section7.12.CreatingaButtonBar
Section7.13.OrientationChanges


Section7.14.WebViewsandScrollers
AppendixA.MiscellaneousHacksandRecipes
SectionA.1.DumpingtheScreen
SectionA.2.DumpingtheUIHierarchy
SectionA.3.InvokingSafari
SectionA.4.InitiatingPhoneCalls
SectionA.5.Vibrating
SectionA.6.TransparentViews
SectionA.7.TakingCameraPhotos
SectionA.8.CoverFlow-StyleAlbumFlipping
Colophon
Index


Copyright
PUBLISHEDBY
MicrosoftPress
ADivisionofMicrosoftCorporation
OneMicrosoftWay
Redmond
Washington
98052-6399
Copyright©2002byMicrosoftCorporation
Allrightsreserved.Nopartofthecontentsofthisbookmaybe
reproducedortransmittedinanyformorbyanymeanswithout
thewrittenpermissionofthepublisher.
LibraryofCongressCataloging-in-PublicationDatapending.
PrintedandboundintheUnitedStatesofAmerica.
123456789QWE765432
DistributedinCanadabyPenguinBooksCanadaLimited.
ACIPcataloguerecordforthisbookisavailablefromtheBritish
Library.
MicrosoftPressbooksareavailablethroughbooksellersand
distributorsworldwide.Forfurtherinformationabout
internationaleditions,contactyourlocalMicrosoftCorporation
officeorcontactMicrosoftPressInternationaldirectlyatfax
(425)936-7329.VisitourWebsiteat
www.microsoft.com/mspress.Sendcommentsto
mspinput@microsoft.com.
Microsoft,MicrosoftPress,MS-DOS,Windows,andWindowsNT
areeitherregisteredtrademarksortrademarksofMicrosoft
CorporationintheUnitedStatesand/orothercountries.Other
productandcompanynamesmentionedhereinmaybethe


trademarksoftheirrespectiveowners.
Theexamplecompanies,organizations,products,domain
names,e-mailaddresses,logos,people,places,andevents
depictedhereinarefictitious.Noassociationwithanyreal
company,organization,product,domainname,e-mailaddress,
logo,person,place,oreventisintendedorshouldbeinferred.
AcquisitionsEditor:DavidClark
ProjectEditor:LynnFinnel


preface
So,youwanttowriteapplicationsfortheiPhone.Thefirstthing
youshouldknowisthattheiPhoneisbyandlargeaclosed
device,andApplehastakenstepstolockusersoutofthe
operatingsystem.Thishasn'tstoppedpeople.InOctober2007,
Appleannouncedinanearningsstatementthatover250,000
unitshadbeensoldwiththeintentofunlockingthemforuseon
othernetworks.Withinthefirstmonthofv1.1'ssoftware
release,NicholasPenree'sjailbreakme.comsiteloggedoverone
millionunitsthatwerefreedtorunthird-partyapplications.
SiteshostingiPhonecrackingtoolshavereportedrecordtraffic,
andevenApple'sownemployeestraipsearoundtheGeniusBar
toutingtheirhackeddevices.Well-respectedhackersjoinedthe
efforttocracktheiPhone,andoncein,realizedit'sjustas
elegantontheinside—awell-plannedmobileplatformwell
worthdevelopingapplicationson.Withinafewmonths,afree,
opensource(http://open-source.org)compilerforbuilding
iPhoneapplicationswasreleased—notbyApple,butbythe
opensourcecommunity.Today,full-featurediPhoneapplications
areubiquitous.Andallofthiswasaccomplishedonadevice
thatwasintendedtobeclosed.
Applefinallywokeuptothefactthatdeveloperswerenot
satisfiedwithSafari-basedapplications.Inlate2007,they
announcedanSDKfortheiPhonetobereleasedthefirst
quarterof2008,butasofthetimeofthiswriting,wedon't
knowwhattheavailabilitywillbe,orwhatrestrictionswillbe
placedonit.Whatwedohavetoday,however,isalmostas
goodandinsomewaysbetter.ThefreeSDK,affectionately
called"thetoolchain,"isn'ttieddownwithlicensing,norisit
exclusivetorunningonlyonApple'soperatingsystem.Infact,a
Linuxuser(andsoonWindowsusers)canbuildandinstall
applicationsontheiriPhonewithoutevertouchingaMac.
Theinterfacesusedbythefreetoolchainareineveryway
identicaltowhatApplemustreleasewiththeirownSDK.The
frameworksavailableontheiPhoneemployastandardsetof


interfacesusedbyApple'spreloadediPhoneapplications.All
majortasksareperformedbytheseframeworks,includingthe
entireuserinterface,playingsoundsandmusic,workingwith
graphicsandanimation,andevendisplayingwebpages.Within
thefirstfewmonthsoftheiPhone'shigh-profilelifeinthepublic
market,theiPhonehackingcommunityextractedthese
interfacesandbuilttheirownsoftwaredevelopmentkit.
Sothisbook,whichwaswrittenbasedonthefreetoolchain,
usesthesamecodethatApple'sXCodeoranyothercompiler
wouldneedtousetocompileiPhoneapplications.ShouldApple
followthroughwiththereleaseofanativeSDK,theclasses,
methods,andexamplespresentedinthisbookareverylikelyto
workwithbothSDKs.Infact,Applewouldhavetorewriteevery
framework—andeverysingleapplicationontheiPhone—to
makethisbookobsolete.
Withtoolchaininhand,andmanysleeplessnightsof
tomhackery,thecommunityhasbeenabletolearnhowtouse
theframeworksandinterfacesavailabletodesignspectacular
third-partyapplications.Thisbookwalksthroughthe
frameworksthatarekeytodesigningthisfull-featuredsoftware
ontheiPhone,withpointerstotoolsthatareavailabletotake
advantageoftheotherframeworksnotdocumentedhere.
TheiPhoneisasuperbdevice,andinspiteofthepolitics
surroundingitsavailabilitytodevelopers,thecommunityis
growingfast.WithorwithoutApple'shelp,theiPhoneislikely
togivebirthtomanycommercialmarketsforitself,and
possiblygrowbeyondthesuccessofitspredecessors,the
PocketPCsandtheSymbiansthatformerlyownedthemobile
marketspace.
Asyoureadthisbook,youprobablywon'trealizejusthowgood
you'vegotit.Thesimplicityyou'llseeinthisbookreflects
thousandsofhoursofworkbytheactivedevelopment
communitychippingawayatthenearlyimpossiblechallenges
thatwereinvolvedinthistask.Theoldschoolmethodsfor
gettinganythingdoneontheiPhonewerelaboriousifnot


exhausting,andcouldhavefilledupvolumesofbooksalone.
EvenafterwefiguredouthowtojailbreaktheveryfirstiPhone,
wecouldn'tdoanythingwithituntilwecameupwithagrand
schemetofoolitintorunningSSH.Ittookanothermonth
beyondthatbeforethefirstGUIapplicationwasevenwritten.
Workcontinuestodaytofigureoutmanyoftheproprietary
interfacesontheiPhone,andwewelcomeanyoneintothe
communitywiththeknow-howandperseverancetojoinusin
thisendeavor.

P2.1.AudienceforThisBook
You'llneedsomepriorknowledgeofcodingtofindthisbook
useful.TheiPhoneframeworkusesObjective-C,whichwe'll
introduceyoutoinChapter2.Thegoodnewsisthatyoucan
alsouseCandC++inyourapplications,soanyonewith
preexistingknowledgeshouldbeabletopickituppretty
quickly.Ifyoudon'tunderstandCorC++,therearemany
booksavailableonthesubject.Thisbookisn'taprimerforany
oftheselanguages,butratherisdesignedtoexplainthe
proprietaryclassesandmethodsneededtowriteiPhone-specific
applications.

P2.2.OrganizationoftheMaterial
Chapter1,explainshowtobreakintoyouriPhone.
Chapter2,illustratesthemakeupofaniPhoneapplicationand
howtogetthetoolchainrunningonyourdesktop.
Chapter3,introducesyoutoUIKit,whichisatthecoreof
developingiPhoneapplicationsanduserinterfaces.
Chapter4,coversbasicgeometricconceptsasusedintheCore
Graphicsframeworkandeventnotifications.
Chapter5,goesdeeperintoiPhonedevelopmentbyexploring
rawvideosurfacesand3-Dtransformations.


Chapter6,coversthemanydifferentwaystorecordandplay
soundsandoutputadigitalaudiostream.
Chapter7,illustratesmanyoftheadvanceduserinterface
componentsofUIKit.
TheAppendixhighlightsmanymiscellaneoushacksandopen
sourceclassestodocoolthingsinyouriPhoneapplication.

P2.3.ConventionsUsedinThisBook
Thefollowingtypographicalconventionsareusedinthisbook:
Plaintext
Usedformenutitles,menuoptions,menubuttons,and
keyboardaccelerators.

Italic
Indicatesnewterms,URLs,filenames,Unixutilities,and
command-lineoptions.

Constantwidth
Indicatesthecontentsoffiles,theoutputfromcommands,
variables,types,classes,namespaces,methods,values,
objects,andgenerallyanythingfoundinprograms.

Constantwidthbold
Showscommandsorothertextthatshouldbetyped
literallybytheuser,andpartsofcodeorfileshighlightedto
standoutfordiscussion.


Constantwidthitalic
Showstextthatshouldbereplacedwithuser-supplied
values.
Thisiconsignifiesatip,suggestion,orgeneral
note.

Thisiconindicatesawarningorcaution.

P2.4.UsingCodeExamples
Thisbookisheretohelpyougetyourjobdone.Ingeneral,you
mayusethecodeinthisbookinyourprogramsand
documentation.Youdonotneedtocontactusforpermission
unlessyou'rereproducingasignificantportionofthecode.For
example,writingaprogramthatusesseveralchunksofcode
fromthisbookdoesnotrequirepermission.Sellingor
distributingaCD-ROMofexamplesfromO'Reillybooksdoes
requirepermission.Answeringaquestionbycitingthisbook
andquotingexamplecodedoesnotrequirepermission.
Incorporatingasignificantamountofexamplecodefromthis
bookintoyourproduct'sdocumentationdoesrequire
permission.
Weappreciate,butdonotrequire,attribution.Anattribution
usuallyincludesthetitle,author,publisher,andISBN.For
example:"iPhoneOpenApplicationDevelopmentbyJonathan
Zdziarski.Copyright2008JonathanZdziarski,978-0-59651855-4."
Ifyoufeelyouruseofcodeexamplesfallsoutsidefairuseor
thepermissiongivenabove,feelfreetocontactusat


permissions@oreilly.com.

P2.5.Safari®BooksOnline
WhenyouseeaSafari®BooksOnlineicononthecoverofyour
favoritetechnologybook,thatmeansthebookisavailable
onlinethroughtheO'ReillyNetworkSafariBookshelf.
Safarioffersasolutionthat'sbetterthane-books.It'savirtual
librarythatletsyoueasilysearchthousandsoftoptechbooks,
cutandpastecodesamples,downloadchapters,andfindquick
answerswhenyouneedthemostaccurate,currentinformation.
Tryitforfreeathttp://safari.oreilly.com.

P2.6.LegalDisclaimer
Thetechnologiesdiscussedinthispublication,thelimitationson
thesetechnologiesthatthetechnologyandcontentownersseek
toimpose,andthelawsactuallylimitingtheuseofthese
technologiesareconstantlychanging.Thus,someofthe
projectsdescribedinthispublicationmaynotwork,maycause
unintendedharmtoequipmentorsystemsonwhichtheyare
used,ormaybeinconsistentwithapplicablelaworuser
agreements.Youruseoftheseprojectsisatyourownrisk,and
O'ReillyMedia,Inc.disclaimsresponsibilityforanydamageor
expenseresultingfromtheiruse.Inanyevent,youshouldtake
carethatyouruseoftheseprojectsdoesnotviolateany
applicablelaws,includingcopyrightlaws.

P2.7.We'dLiketoHearfromYou
Pleaseaddresscommentsandquestionsconcerningthisbookto
thepublisher:
O'ReillyMedia,Inc.
1005GravensteinHighwayNorth
Sebastopol,CA95472
800-998-9938(intheUnitedStatesorCanada)
707-829-0515(internationalorlocal)


707-829-0104(fax)
Wehaveawebpageforthisbook,wherewelisterrata,
examples,andanyadditionalinformation.Youcanaccessthis
pageat:
http://www.oreilly.com/catalog/9780596518554/
Tocommentorasktechnicalquestionsaboutthisbook,send
emailto:
bookquestions@oreilly.com
Formoreinformationaboutourbooks,conferences,Resource
Centers,andtheO'ReillyNetwork,seeourwebsiteat:
http://www.oreilly.com

P2.8.Acknowledgments
SpecialthankstoPatrickWalton,BrianWhitman,JohnBafford,
NicholasPenree,ElliotKroo,DinoPastos,NateTrue,Steve
Dunham,NicolasBacca,DanielPeebles,AlexanderPick,
PiergiorgioZambrini,AaronAlexander,RichardThally,Justin
Lazarow,ChrisZimman,EricMcDonald,andmanyothers
wishingtoremainanonymousintheiPhonedevelopment
communitywhohavecontributedsleeplessnights,greathumor,
andcashfromtheirownpocketstoopentheiPhoneandbuilda
solidfoundationforapplicationdevelopment.


Chapter1.BreakingIntoandSettingUp
theiPhone
TheiPhoneisacloseddevice.Wecan'tsaythisenough.Upto
andincludingversion1.1.xoftheiPhonesoftware,usershave
beenlockedoutoftheoperatingsystem.Thisdoesn'tseemto
stopamajorityofiPhoneusers,butdoesmakeitmoredifficult
togetstarted.Beforehackingofanykindcantakeplace,
however,theiPhonemustbebrokenfreefromitsjail—literally.
TheiPhonerunsinachrootedenvironment,wherenouseror
desktopapplication—eveniTunes—canseeintotheoperating
system;thisiscommonlyknownintheUnixworldasachroot
jail.Thisjail(andthefactthatyoucan'tsimplyyankoutthe
harddrive)istheonlythingstandinginthewayoftheiPhone
functioningasacomplete,portableMacOSXcomputer.
Fortunately,manyfreetoolshavebeenwrittentomakethe
jailbreakingprocesssimple.
Inthischapter,you'llstageyouriPhoneforsoftware
development.Thisincludesbreakingfreefromthechrootjail
(calledjailbreaking)soyoucanaccessthefilesystem.You'llalso
installaBSDUnixworld,whichisasetofcommonUnixbinaries
suchaslsandcp.Thisallowsyoutonavigateandmanagethe
iPhone'soperatingsystem,whichisbelievedtobeaversionof
MacOSX10.5(Leopard)forthearmprocessor.Finally,you'll
getasecurelogincommandenvironment,SSH,upand
running.ThisisusefulforcopyingfilestoandfromyouriPhone,
andwe'lluseittoinstallapplicationsandrunexamples.

1.1.JailbreakProcedures
HowyoujailbreakyouriPhonedependslargelyonwhatversion
ofthesoftwareyouarerunning.Thereisalagtimeofafew
weeksbetweennewiPhonesoftwarereleasesandpublichacks
tojailbreakthem.Smallchangesaregenerallyintroducedin
newversionstomakebreakingintoitalittlebithardereach


time.Thegoodnewsisthatonceanewjailbreakhasbeen
written,allofthefreetoolsavailableareupdatedtomakeit
possibleforjustaboutanyonetogothroughtheprocess.

1.1.1.Third-PartyJailbreakSoftware
TherearemanyfreetoolsavailabletojailbreaktheiPhone,
somemorereliablethanothers.Thebesttoolsarefull-service
utilitiesthatalsoallowyoutosetupashellandinstallthird
partysoftwarewithlittleeffort.Thebestofbreedtoolsinclude:
iNdependence,http://code.google.com/p/independence/
(v1.0.0–1.1.3)
iNdependenceisautilityforMacOSXthatperforms
jailbreak,activation,SSHinstallation,andeveninstallation
ofringtones,wallpaper,andthird-partyapplicationsonthe
iPhone.iNdependenceisundertheGPL,andtheauthorhas
madealibraryavailablecalledlibPhoneInteraction,allowing
developerstowriteothertoolstocommunicatewiththe
iPhone.

AppSnapp,http://www.jailbreakme.com(v1.1.1only)
Usersrunningversion1.1.1oftheiPhonefirmwarecan
navigatetothiswebsiteusingtheiriPhoneandhavethe
entirejailbreakprocessperformedremotely.AppSnapp
takesadvantageofavulnerabilityinoneoftheiPhone's
imagelibrariestobreakintothephone.What'scoolabout
thissiteisthatitnotonlyjailbreaksyourphone,butitalso
fixesthevulnerabilitysothatnobodyelsecanmaliciously
takeadvantageofthephone.Version1.1.1andlaterof
AppSnappalsopatchtheiPhonesoftwaretoallowthirdpartyapplications,andinstallsAppTapp,theNullRiver
installer,whichcanthenbeusedtostageyouriPhonefor
development.


AppTapp,http://iphone.nullriver.com(v1.0.0–1.0.2)
NullriverisasoftwaremanufactureroutofOntario,Canada,
andthedesignerofapackageinstallerfortheiPhone.
InstallerallowsyoutoinstallanyapplicationonyouriPhone
thatisincludedintheirrepositoryusingafeweasytaps.
Theinstallersoftwareitselfworkswithmostversionsofthe
iPhonesoftware,buttheinstaller'sinstaller(ifthatmakes
sense)iscapableonlyofjailbreakingiPhonefirmware
v1.0.x.Theprevioustoolinthislist,AppSnapp,
automaticallyinstallsAppTapponv1.1.1devices.AppTapp
isalsousefulforthesoftwaredowngradeprocedure,
explainednext.

ZiPhone,http://www.ziphone.org(v1.0.0-v1.1.3)
ZiPhoneisajailbreaktechniquedevelopedbytheiPhone
DevTeam.Itwaskeptunderaheavyshroudofsecrecyin
anticipationoftheAppleSDK,butitwaseventuallyleaked
byoneofthedevteam'sformermembers.ZiPhonehas
sincebeendevelopedbeyondasimplejailbreaktechnique
andmanyotherutilitieshavebeenaddedtoit,includinga
fullunlockforalliPhonesuptoOTB(Out-of-the-Box)
v1.1.3.

1.1.2.DowngradingiPhoneSoftware
ThelatestversionofiPhonesoftwareasofthetimeofthis
writingisv1.1.3.Ifyouhaveanewerversion,checktheweb
sitesforthetoolslistedintheprevioussectiontoseewhether
theyhavebeenupdatedtosupportyourversion.Ifnojailbreak
existsforyourfirmwareversion,you'llneedtodowngradetoan
olderversiontogainaccesstoyouriPhone.
iTunessportsafeaturethatallowsuserstodowngradetheir
software,soifyouwindupwithaniPhonerunningsoftware
thathasn'thadajailbreakwrittenforityet,youcanusually


downgradetothelatestbreakableversion.Theinstructions
herehavebeentestedwithiTunesuptoversion7.5.It's
possiblethatnewerversionsofiTunesmayremoveorchange
thisfeature,butsofar,therehavebeennosignsfromApple
thatthiswillhappen.Intheeventthatitdoes,runninganolder
versionofiTunesmightwork.

1.1.2.1.Preparingfordowngrade
TodowngradetheiPhone'ssoftware,you'llfirstneedacopyof
theolderversion.Ideally,you'llwanttogetacopyofwhatever
thenewest,breakableversionofthesoftwareis,basedonthe
versionssupportedbytheapplicationsintheprevioussection
"Section1.1.1."ThesecanbedownloadeddirectlyfromApple's
distributionservers,butyou'llhavetoknowtheURL.Theweb
sitehttp://iphone.unlock.nomaintainsalistofup-to-date
downloadlinksforallversionsoftheiPhonefirmware.
You'llalsoneedacopyofthelatestiPhoneUtilityClient(iPHUC)
availableinthe"downloads"sectionoftheiPhone-Elitesiteat
http://code.google.com/p/iphone-elite/.TheiPhoneUtility
Clientisatoolforperforminglow-levelfunctionsontheiPhone,
suchasbootingoutofrecoverymodeandsendingdevice
firmwareupdates,usedintheinstructionstofollow.
ThedowngradeprocessrestoresyouriPhonetoa
factorystate,soanysavedmessages,recent
calls,orotherdatawillbecompletelyerased.Be
sureyou'vesyncedandbackedupyourcontacts
andcalendar.BesuretousetheImageCapture
utilitytoimportanyphotosyou'vetaken.

1.1.2.2.Downgradingthesoftware
Performthesestepstodowngradetotheolderversionyou've
downloaded:


1. ConnectyouriPhonetothedockandstartiTunes.Ifitsyncs
onconnect,waituntilithasfinishedsyncing.
2. ExtractthecontentsoftheiPhonefirmwarefileyou
downloadedearlier.Thefilewillhavean.ipswextension,
butitisactuallya.ziparchive.Youcanuseunzipfromthe
commandline,oryourfavoritegraphicalarchivalutility.
3. LocatethefileinthearchivebeginningwithWTF,for
example,WTF.s5l8900xall.RELEASE.dfu.Thisisthefile
neededtoplacetheiPhoneintoadevicefirmwareupdate
mode.CopyitintothesamedirectoryasyouriPHUCtool.
4. LaunchiPHUCfromacommandline.Typeenterrecovery
andpressEnter.ThiswillputtheiPhoneintorecovery
mode.
5. QuitiPHUCandthenre-launchit.Theavailablecommands
willhavenowchanged.Usethefilecopytophone
commandtosendtheWTFfiletotheiPhone.Forexample,
filecopytophoneWTF.s5l8900xall.RELEASE.dfu.Press
Enter.NowtypecmdgoandpressEnteragain.Thiswill
placetheiPhoneinto"devicefirmwareupdate"mode.
6. LaunchiTunes.Youwillbegiventhemessagethatan
iPhonewasdiscoveredinrecoverymode.Ifyou'reona
mac,holdtheOptionkeyandclickRestore.Ifyou'reona
PC,holdtheShiftkeyandclickRestore.Youwillbe
presentedwithafileselectionwindow.Locateandselect
the.ipswfileyoudownloaded.
7. YouriPhonewillrestorebacktotheversionofthefirmware
you'vechosen.
8. AftertheiPhonehasfinishedrestoring,youmayreceivean
error1015.Ifthishappens,theiPhonewillbootinto
recoverymode.Tofixthis,usetheiPHUCclientoncemore
andissuethefollowingcommands(besuretoescapethe
spacesasshownbelow):


cmdsetenv\auto-boot\true
cmdsaveenv
cmdfsboot
cmdbootx

1.1.3.InstallingSSH
OnceyouhavejailbrokenyouriPhone,installingaSecureShell
willallowyoutoaccessyouriPhone'sUnixenvironmentand
easilycopyfilestoandfromthephoneoveraWiFiconnection.
UsingSSHrequiresthatyouriPhonebeconnectedtothesame
WiFinetworkasyourdesktopmachine.Ifyoudon'thaveaccess
toaWiFinetwork,you'llneedtouseatoolsuchas
iNdependencetoinstallapplicationsonyouriPhoneinstead,so
youcanskipthissection.Youmight,however,consider
installingMobileTerminal,afreeterminalprogramforthe
iPhone.ThiswillatleastallowyoutoworkintheiPhone'sUnix
environment,whichisnecessarytorunasmallnumberof
examples.MobileTerminalcanbedownloadedfrom
http://code.google.com/p/mobileterminal/.
IfyouusediNdependencetoperformajailbreak,OpenSSHcan
beinstalledatthetouchofabutton—namely,theSSHbutton.
Clickitandfollowtheinstallationprocedure.Ifyouused
AppSnaporAppTapp,installSSHasfollows:
1. AppSnappandAppTapploadasoftwareinstalleraspartof
theirroutine.Onceyou'vecompletedtheirjailbreakand
setupprocess,youshouldhaveanewicononyouriPhone
calledInstaller.Presstheicontoruntheinstaller
application.Theinstallermayinitiallypromptyoutoupdate
itself.Ifthisisthecase,continuethroughtheupdate
procedureandrestarttheinstaller.
2. Youwillbepresentedwithacategorylist.Choosethe
SourcescategoryandselecttheCommunitySources


package.PresstheInstallbuttonattheupperrightofthe
screenandthepackagewillbedownloadedandinstalled.
3. Restarttheinstaller.YoushouldnowseeaSystemcategory.
ChoosethisandinstalltheOpenSSHpackage.After
installing,restartyouriPhone.
SSHshouldnowberunningontheiPhone,butbeforeyoucan
connecttoit,you'llneedtoknowyouriPhone'sIPaddresson
thelocalWiFinetwork.Tofindthis,dothefollowing:
1. TaptheSettingsapplicationonyouriPhone.
2. SelecttheGeneraltab,thenNetwork,thenWi-Fi.
3. YourWiFinetworkshouldappearinthelistwithablue
disclosurearrowtotheright.
4. Pressthebluearrow.You'llbepresentedwithascreen
containingyourIPaddress.
SetupyourIPaddressinthehostsfileonyourdesktopto
simplifyconnectivity.Ifyou'reusingMacOSXorUnix,youcan
edityour/etc/hostsfile.Ifyou'reusingWindowsXP,editor
createthefileC:\WINDOWS\system32\drivers\etc\hosts.Add
thefollowinglinetoyourfile:
x.x.x.xiphone

wherex.x.x.xrepresentstheIPaddressoftheiPhone.
You'renowreadytoconnecttoyouriPhoneusinganSSHclient.
Ifyou'reusingMacOSXorLinuxwithSSHpreinstalled,you
candothisfromaterminalwindow.
$ssh-lrootiphone


Ifyou'reusingWindowsXP,you'llneedtodownloadanSSH
client.OneofthemostpopularfreeclientsisPuTTY,availableat
http://www.chiark.greenend.org.uk/~sgtatham/putty/.
DependingonwhichversionoftheiPhonesoftwareyou're
running,thedefaultrootpasswordiseitherdottieoralpine.
Onceloggedin,youshouldbedroppedtoashellprompt.


Chapter1.BreakingIntoandSettingUp
theiPhone
TheiPhoneisacloseddevice.Wecan'tsaythisenough.Upto
andincludingversion1.1.xoftheiPhonesoftware,usershave
beenlockedoutoftheoperatingsystem.Thisdoesn'tseemto
stopamajorityofiPhoneusers,butdoesmakeitmoredifficult
togetstarted.Beforehackingofanykindcantakeplace,
however,theiPhonemustbebrokenfreefromitsjail—literally.
TheiPhonerunsinachrootedenvironment,wherenouseror
desktopapplication—eveniTunes—canseeintotheoperating
system;thisiscommonlyknownintheUnixworldasachroot
jail.Thisjail(andthefactthatyoucan'tsimplyyankoutthe
harddrive)istheonlythingstandinginthewayoftheiPhone
functioningasacomplete,portableMacOSXcomputer.
Fortunately,manyfreetoolshavebeenwrittentomakethe
jailbreakingprocesssimple.
Inthischapter,you'llstageyouriPhoneforsoftware
development.Thisincludesbreakingfreefromthechrootjail
(calledjailbreaking)soyoucanaccessthefilesystem.You'llalso
installaBSDUnixworld,whichisasetofcommonUnixbinaries
suchaslsandcp.Thisallowsyoutonavigateandmanagethe
iPhone'soperatingsystem,whichisbelievedtobeaversionof
MacOSX10.5(Leopard)forthearmprocessor.Finally,you'll
getasecurelogincommandenvironment,SSH,upand
running.ThisisusefulforcopyingfilestoandfromyouriPhone,
andwe'lluseittoinstallapplicationsandrunexamples.

1.1.JailbreakProcedures
HowyoujailbreakyouriPhonedependslargelyonwhatversion
ofthesoftwareyouarerunning.Thereisalagtimeofafew
weeksbetweennewiPhonesoftwarereleasesandpublichacks
tojailbreakthem.Smallchangesaregenerallyintroducedin
newversionstomakebreakingintoitalittlebithardereach


time.Thegoodnewsisthatonceanewjailbreakhasbeen
written,allofthefreetoolsavailableareupdatedtomakeit
possibleforjustaboutanyonetogothroughtheprocess.

1.1.1.Third-PartyJailbreakSoftware
TherearemanyfreetoolsavailabletojailbreaktheiPhone,
somemorereliablethanothers.Thebesttoolsarefull-service
utilitiesthatalsoallowyoutosetupashellandinstallthird
partysoftwarewithlittleeffort.Thebestofbreedtoolsinclude:
iNdependence,http://code.google.com/p/independence/
(v1.0.0–1.1.3)
iNdependenceisautilityforMacOSXthatperforms
jailbreak,activation,SSHinstallation,andeveninstallation
ofringtones,wallpaper,andthird-partyapplicationsonthe
iPhone.iNdependenceisundertheGPL,andtheauthorhas
madealibraryavailablecalledlibPhoneInteraction,allowing
developerstowriteothertoolstocommunicatewiththe
iPhone.

AppSnapp,http://www.jailbreakme.com(v1.1.1only)
Usersrunningversion1.1.1oftheiPhonefirmwarecan
navigatetothiswebsiteusingtheiriPhoneandhavethe
entirejailbreakprocessperformedremotely.AppSnapp
takesadvantageofavulnerabilityinoneoftheiPhone's
imagelibrariestobreakintothephone.What'scoolabout
thissiteisthatitnotonlyjailbreaksyourphone,butitalso
fixesthevulnerabilitysothatnobodyelsecanmaliciously
takeadvantageofthephone.Version1.1.1andlaterof
AppSnappalsopatchtheiPhonesoftwaretoallowthirdpartyapplications,andinstallsAppTapp,theNullRiver
installer,whichcanthenbeusedtostageyouriPhonefor
development.


AppTapp,http://iphone.nullriver.com(v1.0.0–1.0.2)
NullriverisasoftwaremanufactureroutofOntario,Canada,
andthedesignerofapackageinstallerfortheiPhone.
InstallerallowsyoutoinstallanyapplicationonyouriPhone
thatisincludedintheirrepositoryusingafeweasytaps.
Theinstallersoftwareitselfworkswithmostversionsofthe
iPhonesoftware,buttheinstaller'sinstaller(ifthatmakes
sense)iscapableonlyofjailbreakingiPhonefirmware
v1.0.x.Theprevioustoolinthislist,AppSnapp,
automaticallyinstallsAppTapponv1.1.1devices.AppTapp
isalsousefulforthesoftwaredowngradeprocedure,
explainednext.

ZiPhone,http://www.ziphone.org(v1.0.0-v1.1.3)
ZiPhoneisajailbreaktechniquedevelopedbytheiPhone
DevTeam.Itwaskeptunderaheavyshroudofsecrecyin
anticipationoftheAppleSDK,butitwaseventuallyleaked
byoneofthedevteam'sformermembers.ZiPhonehas
sincebeendevelopedbeyondasimplejailbreaktechnique
andmanyotherutilitieshavebeenaddedtoit,includinga
fullunlockforalliPhonesuptoOTB(Out-of-the-Box)
v1.1.3.

1.1.2.DowngradingiPhoneSoftware
ThelatestversionofiPhonesoftwareasofthetimeofthis
writingisv1.1.3.Ifyouhaveanewerversion,checktheweb
sitesforthetoolslistedintheprevioussectiontoseewhether
theyhavebeenupdatedtosupportyourversion.Ifnojailbreak
existsforyourfirmwareversion,you'llneedtodowngradetoan
olderversiontogainaccesstoyouriPhone.
iTunessportsafeaturethatallowsuserstodowngradetheir
software,soifyouwindupwithaniPhonerunningsoftware
thathasn'thadajailbreakwrittenforityet,youcanusually


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×