ios - How to cancel NSURLSessionDownloadTask with AFURLSessionManager? -


i wanna download pictures afurlsessionmanager in method @selector(collectionaction):

nsurlsessionconfiguration *configuration = [nsurlsessionconfiguration defaultsessionconfiguration]; afurlsessionmanager *manager = [[afurlsessionmanager alloc] initwithsessionconfiguration:configuration];   (int = 0; < _collectionarr.count; ++i) {      nsurl *url = [nsurl urlwithstring:url_address(portnumber,_collectionarr[i])];     nsurlrequest *request = [nsurlrequest requestwithurl:url];      nsurlsessiondownloadtask *downloadtask = [manager downloadtaskwithrequest:request progress:nil destination:^nsurl *(nsurl *targetpath, nsurlresponse *response) {         nsurl *documentsdirectoryurl = [[nsfilemanager defaultmanager] urlfordirectory:nsdocumentdirectory indomain:nsuserdomainmask appropriateforurl:nil create:no error:nil];         return [documentsdirectoryurl urlbyappendingpathcomponent:[response suggestedfilename]];     } completionhandler:^(nsurlresponse *response, nsurl *filepath, nserror *error) {          nslog(@"file downloaded to: %@", filepath);         if (!filepath) {             [manager invalidatesessioncancelingtasks:yes]; //          [manager.operationqueue cancelalloperations];              [self performselector:@selector(collectionaction) withobject:nil afterdelay:request_again_time];             return ;         }         if (i == _collectionarr.count - 1) {             [svprogresshud showimage:nil status:@"done"];         }      }];     [downloadtask resume]; } 

if task has failed, perform selector automatically [self performselector:@selector(collectionaction) withobject:nil afterdelay:request_again_time]; if nothing output this

2014-12-02 11:34:09.711 moneypower[11216:1204579] file downloaded to: (null) 2014-12-02 11:34:12.936 moneypower[11216:1204579] file downloaded to: (null) 2014-12-02 11:34:12.951 moneypower[11216:1204579] file downloaded to: (null) 

and number rolling , rolling, iphone stop working. want cancel tasks if of these tasks failed. with[manager invalidatesessioncancelingtasks:yes]; or [manager.operationqueue cancelalloperations]; have error

2014-12-02 11:34:13.040 moneypower[11216:1204788] *** terminating app due uncaught     exception 'nsinternalinconsistencyexception', reason: 'an instance 0x17947310 of class __nscflocaldownloadtask deallocated while key value observers still registered it. current observation info: <nskeyvalueobservationinfo 0x179449e0> (<nskeyvalueobservance 0x17944b40: observer: 0x1785d3a0, key path: state, options: <new: yes, old: yes, prior: no> context: 0x3992cc, property: 0x179462a0>)' *** first throw call stack:(0x227ddc1f 0x2ffc4c8b 0x227ddb65 0x23485c25 0x2ffded5f 0x2229cb89 0x2ffded5f 0x3055fae1 0x3055fae1 0x836e29 0x8312c9 0x838567 0x839891 0x30685e31 0x30685b84)libc++abi.dylib: terminating uncaught exception of type nsexception 

how should deal it?


Comments

Popular posts from this blog

javascript - Wordpress slider, not displayed 100% width -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -