0

There are a few ways your app can launch:

  1. User opens app
  2. Push notification leads to opening of app.

What is the recommended design to know when to make a async network call to your server to fetch some data? For example, didFinishLaunchingWithOptions gets called at app launcht ime, so would it make sense to put that call in that function? What about putting the call in viewDidLoad of my root view controller? viewDidLoad only gets called once for load while viewWillAppear gets called too frequently.

What's a good pattern or design to handle both cases of app launch.

modusCell
  • 13,151
  • 9
  • 53
  • 80
samonderous
  • 649
  • 1
  • 10
  • 22
  • 1
    it all depends on your need, your services doesn't need authentication at all ? – thndrkiss Aug 13 '14 at 06:58
  • Lets say my root view controller needs some data from my server to populate a collection view. I can get to this view in multiple ways, 1) simply open app, or 2) through a push notification. I want to understand where to put this network call to do the initialization. Now if I put it in didFinish..., I won't know when the call returns, so I need place a spinner on the view and wait until I get a response and reload the collection view. If I put it in viewDidLoad then this will only get called once on view load time. viewWillAppear seems a bit too often. – samonderous Aug 13 '14 at 07:00
  • see this http://stackoverflow.com/questions/5107604/can-somebody-explain-the-process-of-a-uiviewcontroller-birth-which-method-foll it explains different methods getting called before VC loads – thndrkiss Aug 13 '14 at 07:07
  • you can better put it in your view controller's viewDidLoad, call web service, show progress, remove on response of service, reload view accordingly. Does push notification also opens the same view ? – thndrkiss Aug 13 '14 at 07:13
  • Well I considered putting it in viewDidLoad but remember that it's very probable that viewDidLoad will only get called once in the lifecycle if there's no memory pressure. In that case I can't keep refreshing my collection view. Yes, the push notification will also open the same view controller. – samonderous Aug 13 '14 at 07:18
  • can't you put conditions to make service call to happen only once ? – thndrkiss Aug 13 '14 at 07:19
  • Sure but sounds hacky. – samonderous Aug 13 '14 at 07:30
  • yeah best way is to show a loading view controller, a dummy view with your splash image, call your service, show loading view, once service is successful, remove this view controller and load your collection view – thndrkiss Aug 13 '14 at 07:33

0 Answers0