-(Ibaction) Startdownload: (UIButton *) Sender {//nsstring *urlstr = [Nshomedirectory () stringbyappendingpathcomponent:@ "Documents"];NSString *urlstr=@"Http://www.letv.com/ptv/vplay/22929585.html?vfm=bdvppzq&bl=hb#frp=v.baidu.com%2Fshow_intro%2F"; Urlstr=[Urlstr stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; Nsurl*url =[Nsurl Urlwithstring:urlstr]; Nsurlrequest*request =[Nsurlrequest Requestwithurl:url]; Nsurlsessionconfiguration*config =[Nsurlsessionconfiguration defaultsessionconfiguration]; Nsurlsession* Session =[Nsurlsession Sessionwithconfiguration:config]; Nsurlsessiondownloadtask* task = [session downloadtaskwithrequest:request completionhandler:^ (Nsurl *location, Nsurlresponse *response, NSError *error) {Nshttpurlresponse*httpresponse = (nshttpurlresponse*) response; if(httpresponse.statuscode== $) { //NSLog (@ "%@", location);NSString*path = [Nshomedirectory () stringByAppendingPathComponent:@"Documents"]; NSString*filepath = [path stringbyappendingpathcomponent:@"Down.mp4"]; [[Nsfilemanager defaultmanager]moveitematpath:[location path]topath:filepath Error:nil]; NSLog (@"%@", filepath); } }]; [Task resume];}
Download videos on the web using nsurlsession