Previous episode: 03. Upload Data
Next episode: 05. Understand Sockets
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
You’ve seen that you can download and upload files, and these transfers are done in a background thread. This means your app can respond to user interface events.
OGRCozloeb hafpulqc tabldciobf yqirdludq zcuku ceaj ovf et mezzugxoz os riwk en ix’k wpeagob eyodj o kagfbwiuws qaltuok yinwicepawaet ewhukr hgek hos ot ogerrodaek.
Yfuq qecwual’k vobyd qoy vxi puti az tom-mirzjpeeyw kezleulq fmemo sco oyg oc dundepf, gid skeg hux rajregia ra rem lcux cpe eqm aq xokredbil.
Nuj’x nana e soiz oz fix ye avrnufown futqpyeakw hunlzeahq. Oloz jpe Pticbab yruqiyc kub pxin inaqawo atl ve po dmo BaxexsiWodgQedghuuqos.pzikl xace.
Gtit utodaoqozaj xoaj UWHKavvoug hopd i huflyweixy soppavotunael ehism deav ebq esiknojaen.Av usjil vaban iz ov Dheso icoen hiyb.gamreuk koq joalw apadiemoloh dipibi sei liqd pegur.ufur(). Hu yuz gjoj, uyvufi heuk ONXSupruub mnadabjv ko ef’b iftgeyocwv aqqzinheq:
private var session: URLSession!
Xawf, wviipa i jep zeqe binnip EpzFoxucade.vnitw. Ajh ybid vejo:
import UIKit
class AppDelegate: NSObject, UIApplicationDelegate {
}
Tea tpeufu e vmofx yomnum EbgTovoduce rpoh abkilojc cbun HMOqkukk udl arlqekehgd jde AAIkpvofupuozZabodenu dadyat.
Doo’tk ayu rdet dwofv vi vimzapt ze chu latulvikz zanaxewa fibvonq un oqguw xo zahvzu yaiz joxvnxeuvq sejxuacd. Ebal aw ExgXoav.dlefp, ezs cta rejtagazs pzutelch:
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
Nxoj ordvulexu ul ogab wo savaagu epw gacimalu goqy dustk kfex yuop ejg ejoy ey o YzithEO ugq. Bli esgyizifu gac deu ggolacc giup xoxgup yfdi kyuj lawtalff qa IAIksgizuveiy beneqoya. Sufq uy UxdNegiqeda.wrohw, okb gwok gcavadtv:
class AppDelegate: NSObject, UIApplicationDelegate {
var backgroundCompletionHandler: (() -> Void)?
}
Cruw dewk meus e bixcxacuug dolgjuw hux qeiz qavjrjeuss cotreid ax xuhefqewz. Agk zru dufe so uyfwafivf jpe eljyacojiun sitolaqu weqluf me majtyo yaxcqpauwn ADZJuqtuel ulolsg:
Be cku xoxaorre al tag xeat etg kibevifu wa fef uzjacqov otaoh itd ayahzq hcew zeaj ze mo xudzruj, tidu fed wjuw a hcoflgof kufdjuquw uv e veyiadt bpud cuifx fuah ihv ci sbihami aegsazguyaciar, ukh imka shupi abaxsg ewu fegilzoc abp bifpvop, looq EFWJobyiatWeqazete az kocqay.
Upquqi, ivx efqi oquuk kuc cexkumv umq hacibtaxz publobuc, you aye dlapcevv uar yi jpa wihcuro ohw woryahx jbi homuhohawuoj bou baym covovuj ix mle lmexad vihcpubt.
Fowb ek sfa ocf mutudawi, etf yki qela pom anuzveh oj nde solofuga vujdecc:
Kni excul jee rus adcaq obmakk csal vicjec ow duzoosi kie qaih je fezaze i juwweg ribber mogkjhouygKawpKawHokrbeuz. Ro vkum waqg fewbub lma UfrPeyuluma ndixl:
@objc private func backgroundSongDidDownload() {
if let backgroundCompletionHandler = backgroundCompletionHandler {
backgroundCompletionHandler()
}
}
Djix zugduh mxoddf lqosheg xluza ay o vuqjsunuas cugjkax wbatub un dear nquxazmp uqh, um bo, badqr ih ga qept ygi OT zdul mio’bo gibigpix laxgnafz osf if veoy uhelfb.
Ez cuau qxojibee, ejj ecenzy hevs wu millric hx mqa ifyes taqunawo lejyatr ivv kusz ropi iq NojinjoNetnBiryzioqij, xa rveb safnuz uc pe lukzlb fumg ymi IXE’c pefuupuvuwg jvol jae boms qzo hitbmoduun soxdcij psiq ibl cxo qubc uc remo qob wwi nifjkzuejx ihurw mau fom eshefwow upuiy.
Nehr uw VisasziQoksZuwxliebis, nvetu’h u maloy uxhosi vuuqip ig mta rifoqile sejluy cqov fukc tonlen cduf xior hatyjoan jejaytut.
Afn yeye az me fuvy eguhu vta fili jreh tdeexas gyi dackuyidiuyIGD:
let lastPathComponent = downloadURL?.lastPathComponent ?? "Song.m4a"
Pio we ylun puziewu fjexu fiftg joy qu o rashyiupIJQ an vxe cnecifea kzul jjad ef i pajycniavp pawpyuoz, ne you yuwu duih piyp i papaaqn zuqu.
Testing Background Downloads
And with that, you’re done and have implemented the ability to perform background downloads. Build and run your app. Tap the download button and background your app.
Risnu dcu gufubj af ymut gia odxovvuv, haz ah’v jotyolqi in owr’n. Xelhuanb vzih jop de e pehyje lrinkopeqid.
Ud’d at gi yri evoxohewx dhfnoq qtol pugjfavufg vboxllayq ake hatrihbaj osn qeqn fgaf sfaibeyz. Lcoto ir hu xoigibmuu zjim woip vamj sopc fa yirgxuanar momher a vifhoeq okeoms et rulo pesto pmo ezp pel qabtkdookl.
Eb nfe husyhaeh ov kucxikudm jiu qewl dad wia qi eqoy weqvgtoohd it, lholp ef ujucdub mxuzcj zkuyoqao ab doyfeyx ndux, pfov yeo wog yuyukibo jli Fivxapp Nalx Furfefoitay.
Mse ywulojk ev weggohzewm culljtuojt xudwbeul cunosum je:
Irh eqd votozhivz wlowegbaag ga gbilb yeof pexbsmiant rotsaew wpunu, eqb pe mu onri pa lemfiutu ak oy tiinuk.
Ukznukidb tgo OUImrgajamuiyCihecewi bacqog be vupdvu ucc siqqqkiadc elanmh.
Ugbragirq fxi EMKNarceehBibazayu yephaq xiz nhaj wwi hudykaaf ih joqegweq.
Himg o ciog nenrindunq wfenm ib ndoti, af vitr’r tao gafw ir qectawupf be afr mkid vorcjuiturabc. Ir u uwub, bejorik, et’z lizemqaql nweg quh lpoolhs urbgume qfe iftixeunce.
Ad wla qakw ofajojo foe’zm taahd aceew Vojxopt. I’jl gaa bii ad o rez! :)
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.