Search code examples
objective-ciosasihttprequestafnetworking

iOS network operation when app become active


In my current iOS app, I need to perform several network operation when the app becomes active (I'd rather get everything at once than to query things when user click on dedicated tab). I'm using a UIViewController that should be displayed when the app goes to the foreground and handle all network stuff in it.
Is that the recommended way to do it ?

The requests I need to issue are something like:

request1
   if result1
      request2
         request3
   else if result2
      request4
         request3

In order to avoid spaghetti code, is there a lib to use that enable chained requests like those ones? I'm using ASIHttpRequest and I did not find any nice way to perform that (even with queue).


Solution

  • Nothing wrong with that, assuming your UIViewController is some sort of "loading". Perhaps a better way to handle it would be to create a NSObject subclass, and have that handle your network operations, so in the ApplicationDidBecomeActive: you can just fire that off, and still have the sure carrying on with your app.