ios - How do i get the file size to know whether its download or not? -


hi iam using following code downloading epub /pdf url .i give progress bar when start downlaoding shows progress , when download completes popup message ,how can implement ?

my code downloading file

-(void)download  {     nsdata *pdfdata = [[nsdata alloc] initwithcontentsofurl:[nsurl    urlwithstring:@"http://www.feedbooks.com/book/3471.epub"]];      //store data locally epub  file if u want pdf change file extension        nsstring *resourcedocpath = [[nsstring alloc] initwithstring:[[[[nsbundle mainbundle]  resourcepath] stringbydeletinglastpathcomponent] stringbyappendingpathcomponent:@"documents"]];      nsstring *filepath = [resourcedocpath stringbyappendingpathcomponent:@"3471.epub"];      [pdfdata writetofile:filepath atomically:yes];     nslog(@"%@",filepath);  } 

iam using codes in .m file not working me

 -(void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response {     _totalfilesize = response.expectedcontentlength;     responsedata = [[nsmutabledata alloc] init]; }   -(void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {     _receiveddatabytes += [data length];     myprogressbar.progress = _receiveddatabytes / (float)_totalfilesize;     [responsedata appenddata:data]; } 

use nsurlconnection

in .h file

double datalength; nsmutabledata *databuffer; uiprogressview *progress; 

in .m file

-(void)download {       nsurlconnection *con=[[nsurlconnection alloc]initwithrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:@"http://www.feedbooks.com/book/3471.epub"]] delegate:self startimmediately:yes];       [con start]; } 

delegate methods

- (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response {     datalength = [response expectedcontentlength]; }  - (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {     [databuffer appenddata:data];     progress.progress = (databuffer.length/datalength);     self.hud.detailslabeltext = [nsstring stringwithformat:@"downloading  %.f  %%",(databuffer.length/datalength)*100]; } - (void)connectiondidfinishloading:(nsurlconnection *)connection {     nsstring *resourcedocpath = [[nsstring alloc] initwithstring:[[[[nsbundle mainbundle]  resourcepath] stringbydeletinglastpathcomponent] stringbyappendingpathcomponent:@"documents"]];     nsstring *filepath = [resourcedocpath stringbyappendingpathcomponent:@"3471.epub"];     [pdfdata writetofile:filepath atomically:yes];     nslog(@"%@",filepath); } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -