ios - Hit json url link to check any new data after a certain time in objective c -


i need hit json url every 1 week check new data.i tried way.

first take lunching time in milisecond , save in plist,

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {  long currenttime = (long)(nstimeinterval)([[nsdate date] timeintervalsince1970]);     nsdictionary * dict =[nsmutabledictionary new];     paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     documentsdirectory = [paths objectatindex:0];     path = [documentsdirectory stringbyappendingpathcomponent:@"time.plist"];     [dict setvalue:[nsnumber numberwithlong:currenttime] forkey:@"count"];     [dict writetofile:path atomically:yes]; } 

then check in background .if 7 days gone,i fire timer hit json url.

- (void)applicationdidenterbackground:(uiapplication *)application { paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     documentsdirectory = [paths objectatindex:0];     path = [documentsdirectory stringbyappendingpathcomponent:@"json.plist"];      nsdictionary *plistdictionary = [nsdictionary dictionarywithcontentsoffile:path];      long plisttime= [[plistdictionary objectforkey:@"count"] longvalue];     timewithsevendays=plisttime+604800;      timer =   [nstimer scheduledtimerwithtimeinterval:timewithsevendays                                                target: self                                              selector: @selector(checkforupdatejson)                                              userinfo: nil                                               repeats: yes];     [timer fire];  } 

after firing timer,i update plist data current time. if application in foreground in 7 days, create complexity.

should use background service ? background service decrease battery life. or efficient way add appdelegate works foreground , background.

just check new data in didfinishlaunchingwithoptions.

alternative have push notification server let user know there's new content , download when app becomes active.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -