ios - AFNetworking background downloading automatically stop after some time, I need to resume it -
i using afnetwork (its base on nafdownloadrequestoperation) , task in downloading multiple zip files 1 one amazon bucket. when app in foreground every thing working well, when app goes in background mode time downloading running time , automatically stop. read blog in following method called before downloading stop.
[self.operationupdate setshouldexecuteasbackgroundtaskwithexpirationhandler:^{ nslog(@"downloading stop"); }];
- problem in background mode downloading automatically stop
- what want: if downloading stop in background , when app again comes foreground need resume downloading point.
i use following code in appdelegate not understand how resume previous downloading.
__block uibackgroundtaskidentifier backgroundtaskidentifier = [application beginbackgroundtaskwithexpirationhandler:^(void) { [application endbackgroundtask:backgroundtaskidentifier]; nslog(@"applicationwillresignactive"); [__server_instance cancellalldownloading]; // [[yourrestclient sharedclient] cancelallhttpoperations]; }];
if 1 have solution please let me know, in advance.
you should use afdownloadrequestoperation
your request like
afdownloadrequestoperation *operation = [[afdownloadrequestoperation alloc] initwithrequest:request targetpath:path shouldresume:yes]; [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject) { nslog(@"successfully downloaded file %@", path); } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"error: %@", error); }]; [operations addobject:operation];
after restart app, , generate request having same url, resume downloading. "shouldresume:yes" works.
so, on background task can recreate request finish download
__block uibackgroundtaskidentifier backgroundtaskidentifier = [application beginbackgroundtaskwithexpirationhandler:^(void) { [application endbackgroundtask:backgroundtaskidentifier]; nslog(@"applicationwillresignactive"); [__server_instance cancellalldownloading]; // recreate here request finish fownload, //or recreate in when app enter foreground }];
hope helps
Comments
Post a Comment