ios - Check content type when file is done downloading nsurlsessiondownloadtask -


i using nsurlsession manage downloading image/video files. trouble request goes bad , returns text "content not found." how can make sure file thats being downloaded file type requested? (such .jpeg or .mp4)

you can check inside urlsession method didreceiveresponse response property mimetype , check if "image/jpg":

func urlsession(session: nsurlsession, datatask: nsurlsessiondatatask, didreceiveresponse response: nsurlresponse, completionhandler: (nsurlsessionresponsedisposition) -> void) {     if response.mimetype == "image/jpg" || response.mimetype == "image/jpeg" {         completionhandler(nsurlsessionresponsedisposition.becomedownload)     } else {         // code when not jpeg     } } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

node.js - Express and Redis - If session exists for this user, don't allow access -