Sync Data in Background - MultiTreaded Brain melt.

Discussion in 'iOS Programming' started by IDMah, Sep 26, 2013.

  1. IDMah macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #1
    Hi all.

    This is more of a theory or best practices, question.

    I have a Highscore sender getter web service. Which I was planning on staring on the Hight Score view. BUT ! I'd like, if the sender / getter fails, for it to keep working till it updates.. (even after I release calling the view) and while the main game is playing. is the term persist?

    How do I do this without too much book keeping?
    or would it create a zombie child task if I closed the calling view?

    I'm using AFNetworking.
    Sorry if this is basic or my understanding all is wrong..
    Networking, and multitasking hurts my little brain !!

    thanks
    Ian
     
  2. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #2
    So your talking about sending or receiving data over the network?

    Cocoa Touch makes that easy. There is a class, NSURLConnection, that lets you submit requests that are processed in the background, and when they are done, you get notified on the main thread.

    The easiest way to do it would probably be to create a Utilities singleton and have it manage the connection.

    A new method was added to NSURLConnection in iOS 5, sendAsynchronousRequest:queue:completionHandler: You can use that to start a GET or POST, and provide a block of code that gets invoked once the get/post is complete. It's easier to use than the old method of setting up a delegate to the NSURLConnection and handling a number of delegate methods.
     
  3. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #3
    thanks.. Works now I just need to figure out how to trigger the update of the views..

    Will Create a new thread because it's more about me not understanding how to call methods of subviews.

    thanks
    Ian
     
  4. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #4
    A new forum thread, or change your programming to work on a new thread?

    I would strongly advise AGAINST creating new threads to do downloading in the background. Threads are expensive to set up, and tie up physical memory on the device for the lifetime of the thread.

    Apples async upload/download system is designed to provide support for background uploading/downloading WITHOUT creating threads, and Apple STRONGLY encourages you to use it.
     
  5. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #5
    "Question thread" ie. Post .. Sorry for the confusion.
    But Copy that NewThread bad.. will not use.. or try not to..

    thanks
     

Share This Page