Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

waterskier2007

macrumors 68000
Original poster
Jun 19, 2007
1,871
228
Novi, MI
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
 

waterskier2007

macrumors 68000
Original poster
Jun 19, 2007
1,871
228
Novi, MI
Are your HTTP tasks already running on the main thread? If not, how are you splitting them off?

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
 

waterskier2007

macrumors 68000
Original poster
Jun 19, 2007
1,871
228
Novi, MI
Try taking advantage of ASIHTTPRequest asynchronous abilities.

http://allseeing-i.com/ASIHTTPRequest/How-to-use

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?
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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.
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.

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?
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).
 

waterskier2007

macrumors 68000
Original poster
Jun 19, 2007
1,871
228
Novi, MI
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.

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.

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

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

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).

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
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

waterskier2007

macrumors 68000
Original poster
Jun 19, 2007
1,871
228
Novi, MI
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.

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.