objective c - Where is the correct place to make HTTP requests in iOS? -


i have app fetches data server using nsurlsessiondatatask. of right starting http get request in init method of uiviewcontroller displays data. best/smartest place kick off http request? if not, should it?

i'm asking question because when exit app , goes background (and not killed) , re-open application, http request not fired off (because in uiviewcontrollers init method) , data being displayed not date what's on server. i've tried putting in viewdidload method not called upon entering foreground, neither viewwillappear nor viewdidappear.

should doing of http requests in 1 of uiapplications life cycle methods in appdelegate?

in short, best place make http requests in ios?

thank you, can post code or explain more if needed.

first off, huge question , impossible answer here, can point in right direction can learn how fish. :)

to stick model-view-controller paradigm, want create separate object making http requests. http request considered part of model. benefit of being able use model in other ios apps create, example.

as put of stuff , what's best design.... 1 thing strikes me in question want data being displayed in app date on server. on high level, way use ios's ability multitask , perform functions when app in background. need register os app performs fetches server in background.

according apple's documentation, "in xcode 5 , later, declare background modes app supports capabilities tab of project settings. enabling background modes option adds uibackgroundmodes key app’s info.plist file." there need research uiapplicationdelegate's protocol methods – application:performfetchwithcompletionhandler: , -application:handleeventsforbackgroundurlsession:completionhandler:.

also, need nsurlsession little more. if want use background fetching, nsurlsessiondatatask not supported. need use nsurlsessiondownloadtask, save response file , process need to. also, app delegate method name above implies, need read nsurlsessionconfiguration class reference, backgroundsessionconfiguration.

the cool thing of is, after have implemented it, app ui date user – if app killed user or os. pretty nifty.

good luck , hope helps. hope didn't miss other big pieces here.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -