ios - Using NSURLSession to download a lot of images -
i have created simple testing app learn how use nsurlsession. app has download images webservice , present them uitableview. i've written first part of app reads list of images urls web service, now, want display list.
my doubt is:
given list of images long list, ok create nsurlsessiondownloadtask each image? thought create session in cellforrowatindexpath function , store nsurlsessions in nsdictionary using key indexpath of cell (and relying on nsurlcache avoid download same images more once).
other solutions:
i can see 3 more solutions:
using
gcddispatch_asyncsubclassing nsoperation , store
nsoperationimage need download.using third party library
afnetwork... since learning purpose app prefer go code .
if multiple nsurlsession isn't solution, i'd choose 1 of options.
what think approach?
nsurlsessiontask fine large number of downloads. 1 advantage of on of other methods mentioned downloads can cancelled or paused. correctly implements concurrency network operations, more difficult many cats on internet lead believe (if don't believe me, view eskimo's 2010 wwdc session , sample code. nsoperation network connections not trivial).
nsurlsessiontask , friends designed kinds of problems trying solve, , it's tested.
for tableview, start task in tableview:willdisplaycell:forrowatindexpath: , cancel (or pause) task in tableview:didenddisplayingcell:forrowatindexpath:. limit active downloads visible cells.
Comments
Post a Comment