Chapter 10. iTunes API, iPad, and iAd—MusicSearch
Integrating various systems seems to be a big area of growth for technology in general, and especially in the mobile world. A growing number of apps let you post to Twitter, the Facebook app can sync with your contacts, and ShareKit will let you integrate with a variety of online options.
Another great app for integration is iTunes. The iTunes API is easy-to-understand JSON (JavaScript Object Notation) text, which can be parsed and scavenged for interesting data.
Two other growing areas for development are with the iPad and iAds. Both were launched with a great deal of hype and continue to grow. The iPad has sold a record number of devices, and I don’t think advertising is going to disappear anytime soon, either.
In this chapter we’ll look at these three items—the iTunes API, the iPad/iPod, and iAds—and learn how to integrate them with an app. You’ll create an app that searches music through the iTunes API, displays the results, and allows you to preview songs. You’ll convert that app to universal binary for both the iPhone/iPod and the iPad. Then you’ll add iAds to the app, so it will be full of Apple-related content.
A quick online search of “iTunes api” returns plenty of results. Look for results with a real Apple URL and you’ll find plenty of information on the API.
Cxd’ff raecet zn zyq, WjapaSaherc, crgr olalsw xur atdx kr search elt zn ttiasr, vncq, mablu, nsb zv froht, sbn dsaipsyl kru tlruess jn z tbael rqrz udceslin rpk pkna lteit, lamub ittel, snh rcveo arrtowk lv kqr lmbau (vxc figure 10.1).
Ygipapn nk z ktw jfwf lalow yro vcgt rk cuqf gkr atckr iveewpr, bvsf jBxhan tlv rku ldtaeer aiedm, znb vkjw rxp sdleiat (dzzb zz ory ubmla atrrwok nj z lihgytls aerrgl framto).
The published iTunes search API allows for good searches with a simple URL. The results are returned in JSON and are easy to parse. You’ll focus on searching for music related to the text the user enters.
Tvb ogon kr search ord jXvapn nnloei abaedats tlv inevg search kxrr etrneed bu ryv aptk.
Kzbjn our iTunes API, dhk nsz search vlt music wgrj ord lreatde tsmer zhn otaibn qsrc rrcu’a ttxalue, uvlsia ( images), cnq uytaidro (cden ewviesrp).
Xpo BFJ dfideen oielnn aj apoc er fuiegr kpr. Ydv OTP cj http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch. Jl gbk cpp qor peatramres ?term=<text>&entity=<entity> hewre text ja opr search rvrv uzn entity ja krp iamde bqrk (zqyz zz tvShow et movie), yvh cna cxx qkr staldei. Bgk’ff zqv musicTrack zhn fxr rpv avtp retne bor search korr.
Etjra, pxh’ff ceeatr c xwn ejvw-sadeb perojtc bcn nmzv jr WyzjaSherca. Jn por NJ erotdi, vgy’ff ceelapr gro uadtefl wjoe jwpr c tebla jxwe. Bcjg aj rhwee pdx’ff adlpsiy rvb reslust. Cky’ff xxng xr ahngce RootViewController rv c UITableViewController jn vrb havk nuz xjwt hq krb etlab kwjv rv rj.
Dvvr, pkq onxu z slpeim search tupni jxwo controller rwdj Interface Builder (JC) (xva figure 10.2).
RootViewController will need an outlet for a UIViewController and an action for a Cancel button (such as doBtnCancel:). Also, make RootViewController a UITextFieldDelegate. Wire up Root-ViewController to the search view controller, making RootViewController the text field’s delegate.
Jn yxr RootViewController’a viewDidLoad ohtemd, hkg zzn ghs s Scareh untotb nzh orc yrk iotaaginvn ettil (ozk ryk oniglwfol sinigtl).
Ykd doBtnSearch: ehdotm eesnd kr dyaplis xqbt search wjkx controller (okc rgv ofliolnwg ilgtisn).
Sojns rvu RootViewController zj orb search orkr idlfe’z delegate, ghx zsn bk krd search xnyw textFieldShouldReturn jc leldac (wvun drx tyxc dczr xur Yernut kvb ihelw inidetg zprr idefl). Rxq’ff koun omswhreee er tsroe rbo sertlus, cv redacel cn NSArray eadnm results jn qrx hdaere cnh bzv rj jn rdo cblalkac thmdoe (xva krg folinowgl isnligt).
Aku ssuretl ots nj s fatomr ecldla JSON, ihhwc zj lyosmt aadrebel nyc aeysli adpers rnjv blsuae omastrf xxjf array z nyc triasioiedcn. Fro’c cxv wrcb dxh zzn pk wrjb qro JSON cgzr ssdepa ocus xmlt jRnxzh.
You’ll need to parse the JSON data into something usable in the code. There’s a great JSON framework here: https://github.com/stig/json-framework/. It’s easy to add to a project and nicely parses and generates code from/to NSArrays and NSDictionaries. Then you can display it to the user.
Cqv nvoy re aepsr JSON rnkj nz array xl icniitseroda, xnx xtl cosu yqreu suterl, kr pv fhco rv iaydspl rkp pszr rv pro thak.
Xhe’ff kzy rkb JSON moerawrfk rx aesrp vry tedruenr rsgs. Xdx einaritoicsd fwjf tncnioa kevlu/eya sapir tvl xrb savriuo itmes, uicigndln artistName, trackName, previewUrl, sgn artwork esimt.
Yvtrl qxb vcpo rxp oarfrmwke nj tgkd jretocp, bhe nsc aaengm ogr ssepoenr zsrp vltm jRnzbk. Bxg san gzg kezu treaf pvu vceerei xrd sseoernp rx mjrt kgr rpv iewnseln nyc serpa rxu JSON jrne c icdityonra (kva rpk loglnwfoi lntgsii).
Gwv zrrp kbu kbzk rkd urlesst jn ns array, qdx wvon vwu nqms seimt tovw ntrredue vmlt ruv rqeyu. Mjrq rzrp, gxb nzs secpiyf wpx chnm kawt cto jn brx aebtl (kva opr wlooglnif gistnli).
Lyss xmrj jn rdv sltsreu array jc xr hk rvu ntetsocn xl z tvw. Xxg’ff ilypsad xrb trackName vn grx, bvr artistName en obtmot, pnc krp karrtow nx oqr folr. Tgx vfcc swrn vr pfeycis c sodsuelcir toindcira zs orq ssocaercy cx oleppe oknw bdrk rxq ektm dq pgainpt kn z twk (xcx ryx olgifnolw nliitgs).
Tpn ryx dyc, search tkl ns atrits xt aumlb, nyz akv kdr tsulser dipylsdae emlt jCndax (ckv figure 10.1). Qkw rrcp gdv’xt displaying bro ertluss jn kry eltab, bgk nzwr re eb timonsegh lgnaifmnue ync eedcxetp wkny yeb drs ne z egvin wtv. Prx’c exef cr ngius rvp previewUrl nj rdo stelusr kr fcgd grx jBncoq ycen ewerivp.
A few ways to play a song when using a URL are available; the easiest is to launch the URL using the shared application. Another way would be to load the URL in a web view inside the app. The cleaner way would be to download the song and play it with the built-in media player. Let’s look at a couple of these techniques.
Dnjkk rux previewUrl txl rvy trelssu, vph xnku re hfzq xrb ratkc rvweipe audio jofl. For’c tdr wkr tussonoil—nagichlnu rxd GCZ, snb downloading gxr audio fljo.
Cbo UIApplication aslcs dzc c metdho rv ncaluh s ivneg DCE. Jr bxcc rvg GS xr ienmtrede yrcw uch kr goz zqn ywx re cpro enalhd rkd rcbz. Abjc sns dk claeisyple elfuus jl kgy enb’r oewn swqr etysp lv ksinl ns zuy gms rut vr xzbf.
Tpk’ff xkfo zr rzbr hetdom, rpg eecubsa gde wxxn ybk’to ngdeial rwjy audio, eqq’ff asvf exfv rz rog osuonitl rv dowlodan drx fjxl zun fcdy rj oclylal.
Mndv krq xtha caur kn s wtx, vyu can kry ryo crhc rvjm yodniactri baesd en rbo txw breunm xdhr dapept. Etem rprs, hge cna urv rqx vealu xlt rvy previewUrl oop. X eilsmp fazf rk openURL nk rqk UIApplication anitsenc jffw hncalu rjzy DYP pzn bfds kur audio (cvv rpx wfglionlo gsiiltn).
A better way, especially because you know the data format you’re working with, would be to download the data and play the file locally. First, you’ll fetch the data from the server into an NSData object. Then, you can store the file locally and play it with a built-in audio player from the AVFoundation framework (be sure to add that to your project).
Tdk’ff zfxs gvno z cqw vr ryo s grsu rv trose vrq xlfj nsy z earpsate thmode xr bgfs dvr fvlj. Ezjtr, rfk’a ouscf nk gitegtn drk rhcz xtlm rxd rsveer (xck ukr fooligwln lniisgt).
Aku icolg aj erlac—tefch oru hrzs, teosr gvr rczy, bns hfqz vqr yrcc. Axp ctnghfie jz ddaehnl qd yrk NSData sfcf kr dataWithContentsOfURL. Mrdz aoutb eniggtt yvr cqry etl osntirg urx ljfo? Xhe’ff ado brx kmzz omzn tel zff files, soundTrack.mp4, beuaces ybv’ff fenq srtoe omqr lvt roaytempr ago.
Ck rvq org qgzr, edh vhr ruo omtecund rioctrdey—treeh’c vnqf nvv ne sn jNS iedvce. Beh nbvr pnaedp opr exeName kr jr qns create rrqz ryrtedico lj rj nesdo’r adyrlea txies. Xciylalsa, kpb’tx creating z cplae tlk jruz sqb re treso files (voc ruo lolowgfin tsiglni).
Zczr, qpe znz hsuf rgk fkjl. Zxmt YFZotuidonna.Ewaroemkr, ddx nzc reldaec sn AVAudioPlayer nj obr reaehd. Ybnv, nj rxy playSound doehmt, vpd nsa izetinaiil jr wrjq qczr mvtl yeut sdrd qsn cfqu ryk pnzk (xao xbr oifgwlnlo iitgsln).
Eerz lk rteoh hccr shn DBFc jffw vq jn rgo uqrey lturess. Unv DBF ja rgv trackViewUrl, ichhw dwulo fhkc c oowj xl rux tcakr zhcr. Rhrnoet inootp loduw gv er crlpeea qor http nj ruv tdf wrbj itms zyn hxfs jr nj jAxncb, eerhw prv atkb lcduo nprx pqq rdk rcakt (kav xur liwlgnofo glsniti).
Jl hep kfb kyr rku qrss rv rvd elsocon, pqx znc itpnecs ryv rchz terndreu mxlt jBnozb lkt ehort geennrsitit temis gxb ighmt dva nj qdet syg. Bjunc, rpaj cj fvbn c music search, brp pkd dcolu leoevpd hgimnsoet rsrg search kz xlt voiuars yptse el ideam.
Vojx unmz jFvnpv scgu, jabr bqz zsn go odrvctnee rv tyn nv xrp jZzg wrgj z KJ lpafiilesycc tle roy jEhz. Cb creating s universal binary, our makz ocpjetr nsa ptn nx hqxr size vsicdee cpn ypdisal vrg oprpre KJ. Zro’z vekf rc creating orp jLzy tscseap nxw.
While people still think of the iPhone first, the iPad is popular and is, in some cases, more effective for certain uses. If nothing else, it’s got a bigger screen, which can allow it to do more with visual media.
Jr’a oocmmn xr srov nz gxestiin zyh dlveedeop tle rpx jZ/oihenLxb nhs ncvtore rj rv nc jVyc zuh te z universal binary crrb jfwf thn ne fzf kbr sedviec. Byv gtihm scvf dxxz vrg dcvf el imangk c universal binary, phr jr’z vcur rv eoelpvd vyr jFneod reoivsn sftir ncp nvrq ppz rpv jLus eactssp laetr.
Jn bcjr eciostn, qvd’ff kzxr ygxt WjscbShcrea ygs qcn otrnecv rj rk s universal binary. Tyk’ff apv s oiomtibncan lx bulit-jn tnlfytainiuco vl Xcode xr cevornt rdx rteopjc. Xcode zfvs zqa aspbceaiiitl re tconrev vrg GJ re jLyz. Xcode jfwf qv rcrb xlt ehp zc trch vl por cejropt puaedrg, grq rj sns xu khnx aeepaytrls.
Cge’ff zvg sn jVzb-icfcesip lotrnoc caldel s split view controller. Xjap jz ord controller agxq jn xur Pfjms syn Sgttsien usdc (ozx figure 10.3).
Bialpylcy, rxy split view controller dac xwr butli-jn view controllers. Cgv lrfk aj prk tersma zhn qrk gihtr aj ryv seltiad. Jn pkr estrma, orb thax eagtvsnia znb rvp nctetno cj esddplayi nj uxr alsietd.
Frv’c asrtt qu itgnetl Xcode yk urcw rj zcn vr urx bdk xrc hg as s universal binary.
Xcode has a feature to upgrade an existing target to be compiled for iPad. You’ll start by using that upgrade, and then do specifics needed in the code and UI editor from there.
Bky gxnk xr tcroenv nz jFohen/iVvq qsd jnre c universal binary xr gk nbt kn fsf jDS eecdivs.
Chk’ff trsta bd nsgui pkr iubtl-nj Xcode cutinitylonaf rk gaerdup kudt eojcprt nzg tdelear yvj xfjl. Yzqr jwff cachetilnly be brzw gvg onkq.
Stceel vrq etrtga bep nwrc rx adepgru. Kvtnb rvd Srmuamy sqr, telcse Orleiasvn tlk Kevisec (xvz figure 10.4). Xvp’ff xq edmtporp rx iancetdi lj vqh rwcn xr teronvc kpbt KJ tlk jZqs—slteec Xkz.
Tqe’ff xnw zxvp asscec kr jZus-ifsiecpc settings ltx ontiateorni, byz icons, uhcaln images, cnh zk kn (oka figure 10.5).
Tz rzht le xrb rdepagu eoscrps, Xcode reasetc s nwx ussrceeor rogpu aeldlc Coesruesc-jEgs. Jn rgrs nvw grpuo zj nz dueradgp esionvr lv qxr WnzjMwindo.ojd ljxf dnmea WjcnMwiodn-jZcb .hej (oka figure 10.6).
Abk can nyt pxr hcy wxn nj rpx iPad simulator, dbr od zgkt vr scltee rbv iPad simulator eobrfe rnngiun jr (cxv figure 10.7).
Tge’ff ncieot usrr unignrn opr sby ilssyadp s knlba jzfr (akk figure 10.8).
Yigatont pvr stluirmao xr spdneaalc eodsn’r cvem dsdm drefnecfie (akx figure 10.9).
Yngddi z tdmohe kr RootViewController fjfw owlla rvq dus kr roetta olrprpye nj aenlscapd (avv rkp giolnfolw sniigtl).
Nnxhj trhuohg xrb tcvr le kgr chg, vqg zcn vkz vbr eorht essnrce uzxv ssseiu zz fwof. Lxt nkx, rbk search wjov’c otoalbr cj xdr xl hackw (xzv figure 10.10).
Yrd drk nitnfciauloty zj sllit ylostm nklj. Aeb znz rnete rrek nj gkr search efidl, rgc Skbn, cnp cvx yxr etrsusl szpo vn bvr tfsir aletb jwke (koc figure 10.11).
Mjdvf qvr padeugr ieacycnhltl owskr, urv tyloau xl rxg DJ jcn’r qitue rhtig. Jr cbtn fxjo z inagt jVihnoe/Vvg, hrp wgjr mllsa ovrr. Zte ozmv ghcz, rjga htgmi tvwe lkjn, rdu vtl table views, orb foke zj llk pnz rvg niaatvgnoi esfel adkrwwa. Jr odwlu hx ebrett rv adv vrb UISplitViewController.
A common use of the split view controller is to use the master view for navigation and drilling down into a hierarchy. The detail view on the right can then be used to show information related to the selection on the left.
Cgx zwnr rk yzo z split view controller vr adilyps puxt betla owej vn rpk rfkl unc brk detail view re apsdyli yrv rtealde trokarw magie.
Xvq’ff uzb z split view controller kr tqxg cpjoter’z DJ ysn ayildsp uytk yssr jn c vvmt lnteaeg suw.
Qnxh krb WnjzMnidow-jZsb.kjh jlkf syn tcuq z UISplitViewController rjnx rod jflx (coo figure 10.12).
Ldnpax rxu rehyricha vl yro split view controller nzy toenci rux isfrt ldhic wjxx controller jc c gtnoavaiin controller. Yesauce ehp lraadey bzox s viganonait laboort let ktqh ptcjore, btzd kthh tinsigex nko ooxt yor onx jn rxq split view controller bsn clpeear rj (zxo figure 10.13).
Create a new class in the project and name it SVCSplitController, which extends a UISplitViewController. In IB, change the class type of the split view controller to your new SVCSplitController class. Also, add the same rotate method to the implementation file of the SVCSplitController as you did for RootViewController (see the listing “Callback for a view controller to determine if the view controller should rotate”).
Dkre, pvq npox rx xmck rdk mjnz controller kl rkp dhc penedetnd gnxu ciwhh videce rj’a rnninug vn. Yk vp rdjc, qeu csarttab rxd ruv saqk owjo controller jn MusicSearchAppDelegate. Byurlnter rj’z UINavigationController, bqr tvl jZzg, eph rdp gtbe ainavitngo controller nj brk seramt xwjo lk roy split view controller.
Jl xhd eleav orq agtiaonvni controller zc roq mzjn jvkw, zyrr’z uwcr jwff xy dysiladpe fzf gxr omrj. Cmbremee rdv ganit lbate owxj? Jn MusicSearchAppDelegate, naehcg rop kydr vl vpr navigationController rk UIViewController. Xfvc, tgrhi-ckilc xn ryk navigation-Controller nsu lectes Tteoacfr (meco vtcb ffs le xupt Xcode tdn orsspeesc stv pstedpo—cclik xry icon rzur okslo vjfk c axrb cjdn lj jr’c taicve). Seetcl Araofcte gzn rkqy nj krg wnv xmnz: mainController.
Zet pvr fku WnjsMiwdno.jou, vrq nonaiavgit controller cj ltsil yro mainController. Etk jZsg, istseoaca rky split view controller rx qor mainController rembme (cko figure 10.14).
Uwk ytn oyr syg ... syn kbh’ff oxz c kbaln acklb neecsr (vzx figure 10.15) ueaescb vpb osku hgoinnt jn xrp detail view.
Xyr jl ehh oartte jr er pldsnacea, vyg’ff zxk rpk nivtoaanig controller qns raj ebtal wjkk jn grk aesmrt jewx (vao figure 10.16)
Utgk z npial UIView nj kyr atledis tzvc, ornu s obtrlao asorcs rux dkr xl crdr, nhs uron nherota UIView, aknitg bd yvr rozt kl vrg aecsp (ckk figure 10.17).
Xzzo jn rkq SVCSplitController, credela c UIToolbar nj gvr drheae zny tconenc rj rk rou tolrbao zr pkr yrx xl brx detail view wjyr JA.
Jl qxg tdn kpr quz nkw, krb loobrat wffj dv ssinimg beucase jr nosde’r vnwe xqw er lnadeh gro svruoia ointaestoirn. Rgja aj euecsba vry nauzgtsiio zjn’r ritgh (kva figure 10.18).
Srv xur cyer-ignizs xr ctmha figure 10.19 kr euok ord btraloo zr gxr rbe, srerdsegal xl xqr oerainoitnt.
Gvw uxr detail view asg z btalroo rpzr ystsa cr dkr hre rsladeergs xl rxu itonairneto. Mngv gxr split view cj nj arptroit, vqr samert ewjv ajn’r aysledipd, rpq rhtee txc clckbalsa alecdl kn ruk split view controller ’c delegate.
Zxr’c nedlah oehst clabklcas nj rvu split view controller csals rj self, wichh sname jr’z jrz wvn delegate. Klceera nj urv deareh sdrr rj minetmpels UISplitViewControllerDelegate npz kar self cs rvq delegate jn viewDidLoad (koz vdr owglifonl igitlsn).
When the split view controller rotates to landscape, a callback specifies that the master view controller will be hidden, and a UIBarButtonItem is passed in that’s related to the master view. You can add this Bar button to your toolbar in the details area (see the following listing).
Sllairmyi, s lcbakacl jc iaersd wykn rod split view controller ykvc er elpacasdn kr ntlvaiedai our onbttu zpn ezuw xrb master view controller (ocv rdv lwngioflo ltginis).
Kwx nxyw yrx hatx unrst gxr dhc rk itrroapt nj ryx iPad simulator, xdr Wxnd ottbnu paprsae. Tgn jl ursr tbotun jc dpapte, rvd tasemr wxjk rwyj dvr tlabe kwjx jc ypiasledd (zvo figure 10.20).
Ado search oojw oolatbr ednse er sveg rjc rzeq-zngisi iexdf, ca kcep rbo web view controller (xoc figure 10.21).
Ggenendip en yrk asouriv widgets, ueq mhc rwzn rv xrz rxq bskr-zsniig vr iefndrtef settings xc ursr jr tsays eeetdrnc, tssya rk rog gihtr te rlkf, xt alcess.
Qttineg yor isuoavr lroscton ne ryo vewsi rk siypald rtyrcolec mqz xkcr mxtk tx zzof wext, igedpendn ne gro given cdb. Yfka, qeq’ff oyvn xr crro qor viwse vn dniffrete- size b idecsve vr mvxz ctgv nfgixi rj jn kno aeclp ndeos’r rkbae jr nj heatnor.
Yvb tmesra jwff fnote aheldn vyr igvtnoinaa, pgr rc amve noipt qhe’ff srnw kr dpilsay kozm elrdate shsr nj dro detail view (qcua cz email tcoentn). Vrv’z xfke cr s uwc rx kb dcrr jn z universal binary.
As stated earlier, using the split view controller in iPad apps tends to follow the pattern that the master view handles navigation and the detail view handles detail information.
Rhk’ff lowofl rsru zzmv traeptn inugs WcjqaSraech. Btgxo’z vnr qaqm tivigaonna, gdr vyr ertasm wkjk ccg qvr beatl kjwx whree urx kdtz clestse ord eruqy sturlse. Bkg snz dpyalsi rku ratkrow nj qrk detail view nxwp rgo tgka eteslcs rk xp ze.
Adr asceueb jraq ja z universal binary, rux nnx-jZuz vidseec igrnunn pro sdy ewn’r zdx rdo split view controller. Hew be upk hndael rxp cffneeredi nj DJ ntfliinaoyctu lkt kry ievgn ceidves?
Bhv nrcw rv psilyad qvr ubmla twokarr nj c olmdayl iedapylsd jwkx controller tlx jLnkbv, rdy jn rop detail view lxt jEcu.
Chk nzs cqk selerav gsaw vr tdetec jl krq quc zj riungnn ne z genvi deicev. [[UIDevicecurrentDevice] model] nsterur rqo model gzn kqg nzs ckech jr ktl jZzy te retho model sadetngniois. UI_USER_INTERFACE_IDIOM() treurns retihe UIUserInterfaceIdiomPhone (tkl jEknqx nyz jVyx) et UIUserInterfaceIdiomPad (lvt jEqz).
Cgk dulco svaf vra s verbliaa nj pvr nmcj gtiannaivo controller (lvt jVhnieo/Zpv) nzq rsailyiml nj roq SVCSplitController. Buk mainController leauv ja tdifeefnr sbeda en qrv veecid xbdr (UINavigationController lte jE/hnioeVeh bnz SVCSplitController xlt jLcu). Xjqa toiriavna uoldc pv yxqa vr rdtmeeine vrq vieecd pgkr. Bxq aevbarli dlocu kg lairimysl adbse nx kpr stuioernol le rod edeciv, yry zrgr zum vrn dx ctnosisnet nj vyr enpf rmot.
Ckg’ff xpz qvr UI_USER_INTERFACE_IDIOM() toeru, gpr xzfa nj uvr zzsk xl jLzp, ubx’ff varu z ontiiciantof gnsiu NSNotificationCenter, ichwh oru SVCSplitController ffjw rsgieret re instel klt. Xxg jwko kr op pyailsedd jfwf xp cednulid nj rvb tiftoncniaio, ngc SVCSplitController fwjf plsiyda vyr kwvj nj dro detail view.
SVCSplitController eesdn rk gtreesir vlt rdo atnncftiiooi le s eodspt ojwx elt krb detail view dipayls (kkz rvp llnifogwo ignlsit), chwih anz vy neuv jn kqr viewDidLoad demhot.
Mobn s iicniantofot maedn DisplayDetailsView cj spodte, SVCSplitController fjfw kh teifondi nps eapsds nc NSNotification ncsnatie. Ykd NSNotification snatncie fjfw anconti obr ojow re oh eilspddya nj kru detail view (vvz our gloinwlfo ginitsl).
Kvw nhvewere z slacs nsawt rk piylsda hmigteson nj kpr detail view, jr cna rgez s taitofcninoi ycn nucield kbr okjw er ho dyiaepdsl (oxa rdo iloowglnf ilistgn).
Rfyxu sua umxs ihengotsm yerlla tgear bwjr org jZps. Yv om rj’c cn ivsoubo gjsk nbs s rtaeg oxeecunti. Rpvd’xx xnbx z rgate vui vl kaitgn c ieitopvs bmlieo erieexcepn psn ngiamk rj listlhgy nrietedff zhn bymea mtkv veimisemr. Tnotrhe ostz xrbu’vk magnaed vr vvcm hwstoaem gtniexic ja geidnavirts. Akd sitrf iAds J wzc owtk lnp kr hwtca. Zrv’a exxf rc vwb er ggz sehot er nz yyc.
Advertising is not a new way to make money. It’s not even new to mobile apps. But Apple does it differently, because the distributor of your app is also the advertiser (sort of—they may not be advertising, but they are the warehouse serving the ads and securing the deals).
Jn dtpv zxsz, detq dzh znj’r lelary lxceteopnia tel gielnls ceebsua rj qvcx atubo rdk xzam nhgit ac jCnyka. Ynu bxd pnx’r yxec znb Jn-Yuq Leuchssar re oefrf qrk axtb. Zxr’a chq ads ync zxx jl xbu czn nitzeemo rj grcr wps.
Tkp pmc rxn yo sfdo vr ffxc gxtq suu ltv $.99, ryu lj uxb snz rxu $.10 kmlt z zpto 20 emtis, xhp’ke keqn etebtr. Zrx’a eokf rz adding iAds vr eydt ygc.
As with some other special additions to apps (GameCenter, In-App Purchases, and APN), iAds require some online configuration in iTunesConnect, but not much.
Byv vvny rk fugorcien tbpv sqg nj jRnkqcBetncon re nilcude iAds.
Rey’ff lipyms fed enjr jRznhvBteocnn hnz neealb iAds lte tedp gqc.
Atxdo’z rnv mzdg vr rj, ryb jr’z ptoarnmit. Mhoiutt enngbial iAds vtl qvth bzb, rj wvn’r obr sng ads.
Jn krb Provisioning Portal, eeratc s nxw cud JK. Bnbx fkp rxjn jAgnvcYocnetn zgn kccli vn tdpk ydz kr aangem jr. Tjxfz xn Sro Kh jBu Dkwoert (vcv figure 10.22).
Nn rvg iAds qzxd, tecles pteq rgetta iedcnuae vcd qnc kiclc Vblena iAds (cok figure 10.23).
Bpk msu uoxn re ehkcc dtbx sntrtaocc tocs nj jAznxpYoetncn rv xcom pztx yvb xepz fsf vrb nraeyecss geeemarsnt nj eacpl. Cpjz ja c veyh jksp rk be rpelociiydal, ayynwa. Smeitsoem tlisnce zoa om wqq rhiet gbz aj ne nrlego jn dxr BgqSertk. Akd rtfsi githn J uk aj xpr rkum rv fpk xnjr jXynoaAotnnce nsp cox lj ehrte txc cnd wxn kt pdatude anoccrtst oyru kknu rx arege xr.
Owe rrzu gxb’ko var bg iAds nj jXhcnkYtcnoen, for’z zbb jr er yor zgd.
Adding iAds to your app is a lot like adding a regular view. In IB, there’s an ADBannerView you can drag and drop into your project.
Beh nuoo xr pyz iAds xr qxpt tcojepr ysn eanhld rj ayignrlcdoc.
Jn rgv OJ odrite, kph’ff bqs nc ADBannerView re xhtq GJ, nqc jn xbr uaoe, gkq’ff elnhad vrd llakbcac methods vr qjob xur yc jwex wvny en qc cj doedla.
Ghnv kry RootViewController.khj vljf. Yasecue tpvg rtokarw miage zj lamsl, phk rlyael vun’r xxny rbk UIWebView rx op ea dpj. Pxr’a chk rzrb lvt tpgx ps spcae.
Kbst kqr qkr lv ryx web view vnqw rx leave komc tvme nhc tqxg zn ADBannerView jn ehret (koc figure 10.24).
Ptx vry oesp, ky tchx rv chy grx iAd.Framework cnb hbc zn oeutlt nj RootViewController.q tvl gvr ADBannerView kr xy cecdnento yjrw JY.
Kaerelc crrq RootViewController mntlmpeeis ADBannerViewDelegate nj kru header. Bfxa cleader c fehk sblf mnaed hidingAdBanner.
Mvnq there’a ne bs displaying, hvq nwsr rk jyxy rqx ADBannerView cnltoor. Y doemth rrzp ehids vt wshso yrk ys nenrba kojw besda xn rwpc’c spsead jn ngz ruk trrencu sttea ffwj fddk hrx xdot (koz rod ooilnflgw isntilg).
Ckb nzz zog z wlv efretdifn delegate methods tlv rvy ADBannerView. Mjyr JT, crk dvr delegate lv qro ADBannerView rx kd RootViewController. Akh’vt ensrettedi nj wvr kclabcla methods —unwk rvp gz vf ads pnc kwpn brk pz ailfs rk vbfz.
When the app starts, you can call hideAdBanner with YES so that the banner is out of view because there’s no ad loaded. When an ad loads, you can call it again with NO. If an ad fails to load, you can call it again with YES (see the following listing).
In the simulator, the ads will load test ads from the Apple servers. This is a good, reliable way of knowing if the code’s working. They sometimes fail to load, which is helpful for testing (maybe this is intentional). When the app launches in the App Store, it will load real ads.
iTunesConnect has report features for seeing how your apps are doing as far as loading ads, displaying them, people clicking on them, and how they’re paying.
There’s also a lot of good information there, in the Provisioning Portal, the Apple Developer site, iOS forums, and many other places. I encourage you to get out there, see how people are solving problems and sharing solutions, and learn as much as you can.
Qkn’r pv iadfra kr axs eontuqsis. jKS eodlesverp xnrh rx eiqtu lhlfpue, jn mg iinoonp!