ios - NSURLConnection async thread connection closure -


i used nsurlconnection data internet in thread seperated main thread: put in jsonviewcontroller.h :

#import <uikit/uikit.h>  @interface jsonviewcontroller : uiviewcontroller <nsurlconnectiondelegate> {    bool firsttime;    nsmutabledata *_responsedata; } @end 

i use code start connection in jsonviewcontroller.m:

nsurlrequest *request;  if (self.jsonitem == nil) {         request = [nsurlrequest requestwithurl:[nsurl urlwithstring:[nsstring stringwithformat:@"%@%@",my_url,@"testvalue"]]];   }else {         request = [nsurlrequest requestwithurl:[nsurl urlwithstring:[nsstring stringwithformat:@"%@%@",my_url,(nsstring *)self.jsonitem]]];   }   nslog(@"json item = %@",self.jsonitem);     // create url connection , fire request   nsurlconnection *conn = [[nsurlconnection alloc] initwithrequest:request delegate:self]; 

i implement functions related nsurlconnection protocol well:

#pragma mark nsurlconnection delegate methods - (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response {     _responsedata = [[nsmutabledata alloc] init]; }  - (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {     [_responsedata appenddata:data]; }  - (nscachedurlresponse *)connection:(nsurlconnection *)connection                   willcacheresponse:(nscachedurlresponse*)cachedresponse {     return nil; }  - (void)connectiondidfinishloading:(nsurlconnection *)connection {}  - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error {} 

everything works well. question is: after result , connection should finished, why still see small indicator near carrier field above navigation bar? should stop connection manually ?

enter image description here

somewhere in code should find this:

uiapplication* app = [uiapplication sharedapplication]; app.networkactivityindicatorvisible = yes; 

that sets status bar's activity indicator 'on'. when loading finished need turn off again. by:

uiapplication* app = [uiapplication sharedapplication]; app.networkactivityindicatorvisible = no; 

if downloading not more 1 file @ time, add 2 lines connectiondidfinisloading , didfailwitherror method implementations.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -