here fetching data server using method when minimise, app goes in background , after reopen don't see data fetched before, see data first time , when minimise , reopen lost here code
- (void)viewdidload { [super viewdidload]; nsmutableurlrequest *request=[nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"http://198.178.4.9:89/mybite_joomla/cron/webapi.php?task=webapi.viewprofile"]cachepolicy:nsurlrequestreloadignoringlocalandremotecachedata timeoutinterval:10 ]; [request sethttpmethod:@"get"]; [request setvalue:@"application/json;charset=utf-8" forhttpheaderfield:@"content-type"]; nserror *err; nsurlresponse *response; nsdata *responsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&err]; nsdictionary *jsonarray = [nsjsonserialization jsonobjectwithdata:responsedata options: nsjsonreadingmutablecontainers error: &err];{ (nsdictionary *dict in jsonarray) { nametextview.text =[jsonarray valueforkey:@"name"]; usernametextview.text =[jsonarray valueforkey : @"username"]; emailtextview.text=[jsonarray valueforkey : @"email"]; citytextview.text =[jsonarray valueforkey : @"city"]; statetextview.text =[jsonarray valueforkey : @"state"]; countrytextview.text =[jsonarray valueforkey : @"country"]; } }
declare nsdictionary *jsonarray
property (nonatomic,strong)
, use property retrieve data or fill textfields.
second thing if app remains long time in background , in suspended state should have store data in database. because once app got suspended deallocate instance memory.
second main important thing should not use nsurlrequestreloadignoringlocalandremotecachedata
unimplemented.
as apple documentation states,
specifies not should local cache data ignored, proxies , other intermediates should instructed disregard caches far protocol allows. constant unimplemented , shouldn’t used.
so, can pass 0
parameter cachepolicy
or can construct request if timeoutinterval
not mandatory.
nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"http://198.178.4.9:89/mybite_joomla/cron/webapi.php?task=webapi.viewprofile"]];