Problem updating UIProgressView during progress

Discussion in 'iOS Programming' started by waterskier2007, Dec 18, 2012.

  1. macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #1
    Hey guys,

    I am having a problem updating the UIProgressView while I perform some tasks involving HTTP requests. I cant run the other stuff on the background because the app crashes with an error about not running UIKit stuff in the background thread.

    Basically I am doing a bunch of HTTP gets and posts and I want to update my progress bar as i accomplish each set of gets/posts.

    I have tried calling [self performSelectorOnMainThread]
    and passing a method that updates my progress view but it doesn't work. Can anyone provide me with some help. Just ask me for more info on what you need and I will supply it. Thanks so much
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Are your HTTP tasks already running on the main thread? If not, how are you splitting them off?
     
  3. thread starter macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #3
    I am using ASIHTTPRequests and they are all synchronous, on the main thread (I don't specify anything different). I am not very familiar with backgrounding (besides what I have tried to do today), so forgive me if I am not providing the right information
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  5. thread starter macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #5
    I actually tried doing that in an old project of mine. The problem that I ran into is that I put all of my HTTP related methods in another class and use class methods to run them. For this reason I would have to write a ton more code and use instance methods so that my original view would get the delegate/protocol calls when the requests finished. Is that true?
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Is that the case with your current project as well? If not, don't worry about it, unless you feel it makes more sense to separate the HTTP handling.

    If you can take advantage of using blocks, that might help.

    I can't really give you a concrete answer without knowing much more about how your code is structured and being executed (including seeing some actual code).
     
  7. thread starter macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #7
    Yes it helps me have the code that way because it is less clutter in my view controller class. It makes more sense to me that way.

    I just started watching the Paul Hegarty lectures on blocks, so maybe after I finish that I could implement them

    Can't share the code, as it is for work (not my primary task, just a fun side thing with some coworkers. If I really needed to implement the progress bar I would continue to try and figure it out but I will leave it for a later time as it is not critical. Thanks for your help, you seem to be present in every useful thread I visit here
     
  8. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    And even some of the useless ones! ;)

    Thanks for the compliment, though.
     
  9. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    You should always use asynchronous downloads with ASI or other URL downloading classes. For ASI you need basically three callbacks: one for success, one for failure, one for progress. You start the async download on the main thread and it calls you back on the main thread. All the background code is transparent to your code.

    BTW, ASI is now defunct so it would be better to use another class for this, like AFNetworking.
     
  10. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #10
    Or you could use the NSUrlConnection which since iOS 5 has an Async version to.. It uses blocks so it's quite easy to implement :)
     
  11. thread starter macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #11
    I did end up changing some of my larger requests to Asynchronous. Also, what do you mean it is defunct? If it still works, I don't see the problem with using it. Maybe you could elaborate on that. Thanks
     
  12. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008

Share This Page