nstimer - Is Asynchronous NSURLconnection in anyway helpful for real time update or sending constant request to the server in an iOS app? -
nstimer - Is Asynchronous NSURLconnection in anyway helpful for real time update or sending constant request to the server in an iOS app? -
i'm much new objective c. have case need send request server url @ regular intervals. made asynchronous url connection , used nstimer function phone call viewwillappear function.
- (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:@"myurl/test.csv"] cachepolicy:nsurlrequestuseprotocolcachepolicy timeoutinterval:15.0]; nsurlconnection *connection= [[nsurlconnection alloc] initwithrequest:request delegate:self]; if(connection){ label.text = @"connecting..."; }else{ // } } -(void)connection :(nsurlconnection *) connection didreceivedata:(nsdata *)data{ [self viewwillappear:true]; response = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding]; nslog(response); }
i used next nstimer method phone call viewwillappear method.
- (void)checkurlrequest { [self setprogresstimer:[nstimer scheduledtimerwithtimeinterval:(1.0f / 30.0f) target:self selector:@selector(viewwillappear:) userinfo:self repeats:true]]; } - (void)setprogresstimer:(nstimer *)thetimer { [_progresstimer invalidate]; _progresstimer = thetimer; }
is approach correct? because when updated file 'test.csv' on server, can't live update , when file changes still logging old values in file.
i move url connection stuff outside vc , custom class using blocks. allow utilize in other classes , improve oo programming. can send illustration utilize image loading if need it.
ios nstimer nsurl
Comments
Post a Comment