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
Post a Comment